Wkhtmltopdf page height

I am using the excellent wkhtmltopdf tool for rendering HTML to nice PDF documents (done with PHP). Now I need to know if the rendered HTML page will match "one page" in the PDF. I found out that wkhtmltopdf will display ~ 1100px height on one page with my current settings.

I got the idea to use wkhtml2image first. Then I can get the dimensions of the image which works great.

Unfortunately, it takes a long time to render the image, and since I have to do it in a loop, I'm looking for a faster way to do it.

Do you know of any tool that will render HTML using webkit and return the dimensions of the resulting document? It might also be possible to use JavaScript as a helper (write measurements to a div that can be retrieved after), but I can't find a tool that does the job.

Any ideas or alternative approaches?


source to share

1 answer

As far as I know, there is no reliable way to count pages before generating the PDF file itself. It has to do with how WebKit creates lines and how pages break or something ( more details here ).

However, you can use another tool to count the pages in the already generated PDF.

You can also see @my other extensive post on WKHTMLTOPDF here HTML2PDF to PHP - convert utilities and scripts - examples and demos . Perhaps you will find some useful information there, and my code there also contains the page count on the already generated PDF file (FPDF / FPDI implementation in the process of encrypting it).



All Articles