Displaying PDF on the Page.aspx

Topics: Controls
Jan 8, 2012 at 7:08 PM

Hi All!

I can see that when you insert an image, the code calls "image.axd?picture=picture.path" and the image is displayed on page at view mode.

What do I need to modify so that when I insert a PDF file, it will display the PDF at view mode?

By using the controls provided on this link (http://www.beansoftware.com/ASP.NET-Tutorials/PDF-View-Custom-Control.aspx) I can display a PDF right on Page.aspx but the path on the PDF file is hard coded. I can modify this code to make it work but I think there is a more elegant solution.

Can someone please guide me thru adding an HTTP handler so the PDF file will display right on the Page.aspx? The way I envision this to work is like inserting an image. When I insert a PDF file on a page, the PDF file is stored in /App_Data/files/Year/Month/ folder. And then at view mode, the HTTP handler displays the PDF file.

To make it simple, when I insert a PDF file, that is all I expect to display  - nothing else.


Jan 8, 2012 at 11:18 PM
Edited Jan 8, 2012 at 11:50 PM

I got the PDF to display by modifying the ServePage method of Page.aspx as shown below:

            if (arg.Body.Contains(".pdf"))
                string path = arg.Body.Substring(arg.Body.IndexOf("file.axd?",0));
                path = path.Substring(0, path.IndexOf("pdf", 0) + 3);
                this.ShowPdf1.FilePath = path;
                this.divText.Visible = false;
                this.ShowPdf1.Visible = true;
                this.divText.InnerHtml = arg.Body;
                this.divText.Visible = true;
                this.ShowPdf1.Visible = false;

BUT my web site is too slow... on FireFox! Using Firebug, it shows the the pdf is downloaded everytime the page is visited using Firefox - even on a page refresh.

But on IE, the page loads fast on the second visit. I'm assuming the PDF is getting cached.

So the question really is how do I tell Firefox to cache the PDF file. Is there a cache always setting?

Help please! I thought this would be simple.

Jan 9, 2012 at 3:06 AM

I've tried Response.CacheControl = "public". No help. Firefox is still not caching the PDF.

I also got rid of the 3rd party control and just hard-coded the HTML for the iframe and modified the divText.InnerHTML on the fly. No help.