I have a webpage that attempts to load a PDF file in an iframe. Using my development system the PDF file opens from both my development and production servers. However, when I attempt to open the PDF file on a Windows 7 system that uses IE 9 from the
production server, the PDF file does not open and there is no error message. My development system runs Vista and the PDF file opens using IE 9, Firefox and Safari. I also opened the PDF file using an XP system and IE 8 from the production server.
I don't have a clue if the problem is associated with Windows 7, some setting in the IE 8 browser, or something I should be including in my code.
Here is the code:
<iframe runat="server" id="pdfFrame" style="width: 700px; height: 480px" visible="true" />
*** and the Code Behind ***
Protected Sub gvNews_SelectedIndexChanged(sender As Object, e As EventArgs) Handles gvNews.SelectedIndexChanged
Dim fileName = gvNews.SelectedValue
Dim vPath As String = "/NewsItems/" & fileName
pdfFrame.Attributes.Add("src", vPath)
End Sub
I would appreciate hearing from you and a solution to this problem, thanks.
iframes weren't deprecated because they are a proprietary tag that never was adopted into the standard in the first place. HTML4 only accepts iframe in its transitional doctype because there were so many web pages using it that need to transition it to the
object tag that they didn't want to be reporting it as an error.
To be deprecated implies that the tag was valid in the HTML 3.2 standard and iframe was never been part of that standard. Those developing the HTML 4 standard decided to specify the object tag as the way to perform that function instead. The only reason
why object hasn't completely replaced the need for iframe is that there are still one or two antiquated browsers that don't handle the object tag properly when used for displaying HTML (although it almost works properly in IE6 and 7)
Dim path As String = "D:\Stanly\Admissionhelpline\CollegeDocuments\Adobe.pdf"
Dim client As New WebClient()
Dim buffer As [Byte]() = client.DownloadData(path)
If buffer <> Nothing Then
Response.ContentType = "application/pdf"
Response.AddHeader("content-length", buffer.Length.ToString())
Response.BinaryWrite(buffer)
End If
Thank you for your suggestion; it does open the PDF file as you said. However, I wanted to open it within the existing web page. Is there a way to do this?
I've now attempted to use an object instead of an iframe, but I'm getting a Parser Error Message:
An object tag must contain a Class, ClassID or ProgID attribute. I'm new to the object tag; perhaps you could provide some guidance. Here is my code.
<object runat="server" id="pdfNews" width="700" height="480" type="application/pdf" data="~/NewsItems/CCN 001.pdf">
<p>Sorry, but that news item was not found.</p>
</object>
**** Code Behind ****
Protected Sub gvNews_SelectedIndexChanged(sender As Object, e As EventArgs) Handles gvNews.SelectedIndexChanged
Dim fileName = gvNews.SelectedValue
Dim pPath As String = Request.PhysicalApplicationPath & "NewsItems\" & fileName
pdfNews.Attributes.Add("data", pPath)
End Sub
GrandpaB
Member
389 Points
367 Posts
iframe not loading PDF file
Apr 10, 2012 06:54 PM|LINK
Good afternoon ASP programmers.
I have a webpage that attempts to load a PDF file in an iframe. Using my development system the PDF file opens from both my development and production servers. However, when I attempt to open the PDF file on a Windows 7 system that uses IE 9 from the production server, the PDF file does not open and there is no error message. My development system runs Vista and the PDF file opens using IE 9, Firefox and Safari. I also opened the PDF file using an XP system and IE 8 from the production server.
I don't have a clue if the problem is associated with Windows 7, some setting in the IE 8 browser, or something I should be including in my code.
Here is the code:
<iframe runat="server" id="pdfFrame" style="width: 700px; height: 480px" visible="true" /> *** and the Code Behind *** Protected Sub gvNews_SelectedIndexChanged(sender As Object, e As EventArgs) Handles gvNews.SelectedIndexChanged Dim fileName = gvNews.SelectedValue Dim vPath As String = "/NewsItems/" & fileName pdfFrame.Attributes.Add("src", vPath) End SubI would appreciate hearing from you and a solution to this problem, thanks.
Dino He - MS...
Star
8068 Points
1023 Posts
Microsoft
Re: iframe not loading PDF file
Apr 12, 2012 07:57 AM|LINK
Hi
iframes weren't deprecated because they are a proprietary tag that never was adopted into the standard in the first place. HTML4 only accepts iframe in its transitional doctype because there were so many web pages using it that need to transition it to the object tag that they didn't want to be reporting it as an error.
To be deprecated implies that the tag was valid in the HTML 3.2 standard and iframe was never been part of that standard. Those developing the HTML 4 standard decided to specify the object tag as the way to perform that function instead. The only reason why object hasn't completely replaced the need for iframe is that there are still one or two antiquated browsers that don't handle the object tag properly when used for displaying HTML (although it almost works properly in IE6 and 7)
Iframes break in IE9
And I suggest you use this:
Dim path As String = "D:\Stanly\Admissionhelpline\CollegeDocuments\Adobe.pdf" Dim client As New WebClient() Dim buffer As [Byte]() = client.DownloadData(path) If buffer <> Nothing Then Response.ContentType = "application/pdf" Response.AddHeader("content-length", buffer.Length.ToString()) Response.BinaryWrite(buffer) End IfIf you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework
GrandpaB
Member
389 Points
367 Posts
Re: iframe not loading PDF file
Apr 12, 2012 03:14 PM|LINK
Dino He
Thank you for your suggestion; it does open the PDF file as you said. However, I wanted to open it within the existing web page. Is there a way to do this?
GrandpaB
Member
389 Points
367 Posts
Re: iframe not loading PDF file
Apr 13, 2012 02:20 PM|LINK
Dino He,
I've now attempted to use an object instead of an iframe, but I'm getting a Parser Error Message: An object tag must contain a Class, ClassID or ProgID attribute. I'm new to the object tag; perhaps you could provide some guidance. Here is my code.
<object runat="server" id="pdfNews" width="700" height="480" type="application/pdf" data="~/NewsItems/CCN 001.pdf"> <p>Sorry, but that news item was not found.</p> </object> **** Code Behind **** Protected Sub gvNews_SelectedIndexChanged(sender As Object, e As EventArgs) Handles gvNews.SelectedIndexChanged Dim fileName = gvNews.SelectedValue Dim pPath As String = Request.PhysicalApplicationPath & "NewsItems\" & fileName pdfNews.Attributes.Add("data", pPath) End SubThanks in advance.
GrandpaB
Member
389 Points
367 Posts
Re: iframe not loading PDF file
Apr 15, 2012 03:44 PM|LINK
The object tag is HTML and including the runat="server" parameter confused ASP. Once runat was removed the PDF file loaded.