-
How do you display a .PDF file in the browser?
Hi,
I found this code in MSDN that is supposed to open Adobe Acrobat Reader and
display a .PDF file in the browser. What it actually does for me is to display
the contents of the file--eg %PDF ... (not in Acrobat).
How do I get the file to be opened with Acrobat? (I do have acrobat installed
on the browser machine, and it does successfully display .PDF's from other
web sites)
<%@ Page ContentType="application/pdf" %>
<%@ Import Namespace="System.IO" %>
<script language="vb" runat="server">
Sub Page_Load(sender as Object, e as EventArgs)
Const strFileName as String = "C:\transits.pdf"
' Read the contents of a binary file
Dim objStream as Stream = File.Open(strFileName, FileMode.Open)
Dim buffer(objStream.Length) as Byte
objStream.Read(buffer, 0, objStream.Length)
objStream.Close()
Response.BinaryWrite(buffer)
End Sub
</script>
-
Re: How do you display a .PDF file in the browser?
If the file is already a PDF file, all you need to do is redirect the
browser to it. Every client that has the Acrobat reader installed will
display the file automatically.
"mark erickson" <m1erickson@cs.com> wrote in message
news:3bd5b05a$1@news.devx.com...
>
> Hi,
>
> I found this code in MSDN that is supposed to open Adobe Acrobat Reader
and
> display a .PDF file in the browser. What it actually does for me is to
display
> the contents of the file--eg %PDF ... (not in Acrobat).
>
> How do I get the file to be opened with Acrobat? (I do have acrobat
installed
> on the browser machine, and it does successfully display .PDF's from other
> web sites)
>
>
> <%@ Page ContentType="application/pdf" %>
> <%@ Import Namespace="System.IO" %>
>
> <script language="vb" runat="server">
> Sub Page_Load(sender as Object, e as EventArgs)
> Const strFileName as String = "C:\transits.pdf"
>
> ' Read the contents of a binary file
> Dim objStream as Stream = File.Open(strFileName, FileMode.Open)
>
> Dim buffer(objStream.Length) as Byte
> objStream.Read(buffer, 0, objStream.Length)
> objStream.Close()
>
> Response.BinaryWrite(buffer)
> End Sub
> </script>
>
-
Re: How do you display a .PDF file in the browser?
Not an option if you are, for example loading the pdf file from a non-web
accessible location, ie outside your webroot or from a database table.
Your problem may be that IIS on your server does not have the mime type "application/pdf"
registered.
"Russell Jones" <arj1@northstate.net> wrote:
>If the file is already a PDF file, all you need to do is redirect the
>browser to it. Every client that has the Acrobat reader installed will
>display the file automatically.
>
>"mark erickson" <m1erickson@cs.com> wrote in message
>news:3bd5b05a$1@news.devx.com...
>>
>> Hi,
>>
>> I found this code in MSDN that is supposed to open Adobe Acrobat Reader
>and
>> display a .PDF file in the browser. What it actually does for me is to
>display
>> the contents of the file--eg %PDF ... (not in Acrobat).
>>
>> How do I get the file to be opened with Acrobat? (I do have acrobat
>installed
>> on the browser machine, and it does successfully display .PDF's from other
>> web sites)
>>
>>
>> <%@ Page ContentType="application/pdf" %>
>> <%@ Import Namespace="System.IO" %>
>>
>> <script language="vb" runat="server">
>> Sub Page_Load(sender as Object, e as EventArgs)
>> Const strFileName as String = "C:\transits.pdf"
>>
>> ' Read the contents of a binary file
>> Dim objStream as Stream = File.Open(strFileName, FileMode.Open)
>>
>> Dim buffer(objStream.Length) as Byte
>> objStream.Read(buffer, 0, objStream.Length)
>> objStream.Close()
>>
>> Response.BinaryWrite(buffer)
>> End Sub
>> </script>
>>
>
>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks