0

I'm trying to get a pdf file to display a pdf document in my aspx page with an iframe. I'm using the following code:

<iframe runat="server" id="testpdf" src="http://localhost:1114/pdfs/3211LD.pdf">
</iframe>

When I run the project, I just get an empty frame. However, when I paste the src (http://localhost:1114/pdfs/3211LD.pdf) into the address bar of a browser, it asks me to run/save the file. So I know my virtual directory is set up right.

So why won't it display in an iframe? Is there something wrong with my code?

Thanks, Jason

Alex KeySmith
  • 16,657
  • 11
  • 74
  • 152
  • Found out you gotta be running at least IE8 (my VM had an old version) and an up-to-date copy of Adobe Reader. –  May 06 '11 at 22:55

4 Answers4

0

When a web broswer displays a PDF file, it is actually using an Adobe Reader plugin to render the contents. I have never seen the Adobe Reader plugin run from inside an iframe. I do not believe it works like that.

Katie Kilian
  • 6,815
  • 5
  • 41
  • 64
  • I didn't either, but for the record: –  May 06 '11 at 22:52
  • pnlPDF.Visible = True iFrameControl.ID = "PDFVeiwer" iFrameControl.Attributes.Add("width", "100%") iFrameControl.Attributes.Add("height", "400") iFrameControl.Attributes.Add("runat", "server") iFrameControl.Attributes.Add("scrolling", "auto") iFrameControl.Attributes.Add("align", "middle") iFrameControl.Attributes.Add("frameborder", "1") iFrameControl.Attributes.Add("src", "\\MyServer\Letter_UW_3644700.pdf") pnlPDF.Controls.Add(iFrameControl) –  May 06 '11 at 22:54
0

Youd be better of with an aspx page binary writing the pdf...

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Set the appropriate ContentType.
        Response.ContentType = "Application/pdf"
        'Get the physical path to the file.
        Dim FilePath As String = MapPath("acrobat.pdf")
        'Write the file directly to the HTTP output stream.
        Response.WriteFile(FilePath)
        Response.End()
End Sub
jenson-button-event
  • 18,101
  • 11
  • 89
  • 155
0

You cannot totally control what the browser will do, but if you send out a PDF yourself, you can change the Content-disposition header to inline. Follow @BobTodd's code, but add

 Response.AddHeader("Content-disposition", "inline");

to request that the PDF be showed in the page.

Another way is to do it is to rasterize the PDF pages to png and use a <img> tags inside of a regular web page. You could do this with GhostScript.

Disclaimer: I work at Atalasoft. We make an ASP.NET image viewer web control and a PDF Reader add-on that converts PDF on the server automatically and displays it in web pages without needing Acrobat.

Lou Franco
  • 87,846
  • 14
  • 132
  • 192
0

You need to use the tag to display a PDF within the page (and/or possibly the embed tag)

Here a question that helps in various ways: Recommended way to embed PDF in HTML?

Community
  • 1
  • 1
Mark Redman
  • 24,079
  • 20
  • 92
  • 147