3

I just landed a big contract that includes embedding PDF pages on html pages. I found this question and answer straight away: Recommended way to embed PDF in HTML?

My question is this, is the answer given still the best way to embed a PDF, give that 4 years have passed since it was asked, or is there a newer way to do it?

This seems by far the simplest solution to plant a PDF in the middle of a page, but I could be wrong: http://pdfobject.com/

Ferdia

Community
  • 1
  • 1
Ferdia O'Brien
  • 867
  • 3
  • 10
  • 25
  • Now browsers support html5, – safarov Mar 28 '12 at 16:35
  • I thought of that myself, but unfortunately we are a long way away from being able to rely on the majority of users to view a page in a HTML5 compliment browser. – Ferdia O'Brien Mar 28 '12 at 16:37
  • So there is no reason to search for embeding way for pdf. Unless its pdf to html or rendering – safarov Mar 28 '12 at 16:41
  • PDF's are a PAIN to deal with. I just spent a couple of weeks perfecting a PDF metadata reader for a project I'm working on. None of the ones I could find would handle all the different versions of PDF documents I had to work with. I hope your luck is better than mine. – mseancole Mar 28 '12 at 16:46
  • High showerhead, what sort of variation did you have to deal with? Mine will all be from the same supplier, so that SHOULD mean I don't have a similar problem I hope... – Ferdia O'Brien Mar 28 '12 at 18:06
  • Mine were from the same supplier as well but they were accumulated over years. So different tools were used to put them together or edit existing ones. Different versions, different compilers, it was a mess. Mostly it was just the changes in meta data structure that caused me issues. For instance: the description tag was either upper- or lower-case; could have a text node or a child node li that contained the text node; it could be a child node itself of an upper-case Description node or a lone node underneath the root node, or any combination. And that was just the description tag. – mseancole Mar 28 '12 at 18:24

1 Answers1

2

Check out the XPDF library http://www.foolabs.com/xpdf/. You can also take a look at Poppler http://poppler.freedesktop.org/.

Long story short, you could use the pdftohtml command found in Poppler to generate page-fidelity images of the pdf you're trying to embed. If you want to have page-fidelity HTML versions of the PDF, well... that's an entirely different can of worms. :)

Good luck!

Matthew Blancarte
  • 8,251
  • 2
  • 25
  • 34
  • So, just to confirm, what that does is converts the PDF to an image file on the fly, and embeds it rather than the PDF? Now that's an interesting approach... – Ferdia O'Brien Mar 28 '12 at 18:05
  • Correct! :) All you have to do is run a system command within PHP like `pdfimages -j yourfile.pdf yourhtmltoembed.jpg`. Then, just grab that puppy and pop it on the page as you see fit! – Matthew Blancarte Mar 28 '12 at 18:40