How to achieve Chapter / Section pagination wise in PDF creation using the WKHTMLTOPDF PDF engine

I am trying to create a PDF book using WKHTMLTOPDF for Linux and dining through a Perl program. I am passing multiple html files with cover and footer information via html file to WKHTMLTOPDF command line. When printing to PDF, WKHTMLTOPDF treats each file as one section / section. I can achieve pagination in full PDF with variables using Javascript given in the html footer. But I want to print the page number of the current chapter / section in processing, as well as the total number of pages in that chapter / section. This should actually reset the page counter after the chapter / section has been printed. This information can be useful for displaying the total number of pages in each section and pagination numbering.

Does anyone know how to achieve it? I am using WKHTMLTOPDF patch QT RC11



source to share

2 answers

There are at least two ways to solve your problem.

  • You can specify a value --page-offset

    for each file object. For example:wkhtmltopdf page --page-offset 1 section1.html page --page-offset 1 section2.html

  • You can calculate the number of pages in the current section using the query string provided to the footer of the html script


Use [sitepage]

and [sitepages]

, for example:

wkhtmltopdf.exe file:///C:/temp/html1.html --footer-right "Page [sitepage] of [sitepages]" file:///C:/temp/html2.html --footer-right "Page [sitepage] of [sitepages]" output.pdf



All Articles