1

I'm looking for a way to make sure that the output from wkhtmltopdf always consists of an even number of pages, i.e. adding a blank page at the end of the pdf if the number of pages is uneven. If anyone has a good solutions for this I would be really happy

/J

myterist
  • 11
  • 2

1 Answers1

0

A simple solution would be to create the pdf, then check the page count and add one empty page with for example itext / itextsharp if necessary. Guessing page counts or lengths is very difficult.

Joel Peltonen
  • 13,025
  • 6
  • 64
  • 100
  • I guess that could work, but i prefer not to include another third party SW besides wkhtmltopdf. If was enough problems including and tuning that program to my needs, so what I'm really after is a solution working with plain wkhtmltopdf, js, jquery, C# or similar. – myterist Apr 23 '13 at 12:00
  • Understood. I'll try to think of something else. Wkhtmltopdf page breaking is notorious. If your content is highly predictable, some content calculation could be done, but I it would require that your margins and page size are pretty much static. Some dudes have done page calculation with JS by calculating the content height (page fits ~1800px, my document height is ~6000px etc etc), but it is Very unperdictable in my content and I can't really recommend it before I have tried it myself. – Joel Peltonen Apr 23 '13 at 13:20
  • In https://code.google.com/p/wkhtmltopdf/issues/detail?id=168&q=table%20break there is some releated discussion and height calculations that might be useful. – Joel Peltonen Apr 23 '13 at 13:21
  • Thanks for your good comments but it seams I'm stuck now. I tried counting the pages in the footer with a script and that works perfectly ok. Then I did a MOD 2 operation on that count and found out if the number was uneven, also works fine. But when I tried adding a page-break-after: always; in the footer nothing happens, I guess it's because wkhtmltopdf never breaks the footer :-(. So what I would need at this stage is a way to manipulate the main document from the footer script so I could add my break there. Can I get access to the main document from the footer? – myterist Apr 25 '13 at 09:26