Do I render PDF into HTML, to be printable?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Do I render PDF into HTML, to be printable?

Post by simonmlewis »

I have been asked if there is a way to extract data from the DB, show people's details, and then within the same row, show the PDF that's been uploaded on screen, so the whole page is printable.

The idea is they can select a month of choice, which they can then print off for various authorities.

I've tried this:

Code: Select all

<div id="pdf">
  <object width="50%" height="500" type="application/pdf" data="/test.pdf?#zoom=50&scrollbar=0&toolbar=0&navpanes=0" id="pdf_content">
    <p>Insert your error message here, if the PDF cannot be displayed.</p>
  </object>
</div>
While it shows it on screen, it's not printable.

I also thought about doing it with an iframe, but a) I'm not sure if that will work and b) with iframe, you have to set a height and width. What if the document is taller than the iframe?

Is it not possible?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Do I render PDF into HTML, to be printable?

Post by requinix »

You might be able to do some Javascript trickery to dynamically expand the iframe based on the size of its contents. First, try an iframe to see if it will even print.

Can you convert (perhaps on-the-fly) the pages of the PDFs to images? It would probably require some application be installed on the server, but if you can do that then it should definitely work.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Do I render PDF into HTML, to be printable?

Post by Christopher »

I have found that the most reliable way is to generate both HTML and PDF versions of these pages. The HTML version is displayed and can be printed with Javascript. The PDF can be downloaded on request. Not elegant but necessary.
(#10850)
Post Reply