Page 1 of 1

Do I render PDF into HTML, to be printable?

Posted: Thu Oct 13, 2016 10:12 am
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?

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

Posted: Thu Oct 13, 2016 11:39 am
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.

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

Posted: Fri Oct 14, 2016 12:15 am
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.