Tip on Embedding PDFs in Web Pages – use the right file extension!
I’ve been trying to get a PDF to embed inside of a Web page for most of the day, but I’ve been having problems with most browsers. In IE, the area where the PDF should be is just a blank white box. In Safari, a dialog pops up asking me if I’d like to save the file. Firefox occasionally crashes. Of course Opera works just fine:).
Here’s some HTML that will not work correctly in most browsers:
<p><embed src="/controller/gen/streampdf.html" width="800" height="400"></embed></p>
(Note that in my case I have a server side script that is dynamically generating and streaming the PDF to the browser.)
Here’s the HTML that will work:
<p><embed src="/controller/gen/streampdf.pdf" width="800" height="400"></embed></p>
If you look closely, I changed the extension on the URL to “pdf”. I’m still streaming the exact same bytes with the same response headers, however, having a “.pdf” at the end of the URL apparently makes the browsers happy.
That would have been nice to have known this morning!
Enjoyed this post? Click to get future articles delivered by email or get the RSS feed.
