wkhtmltopdf automatic page breaks
Asked Answered
I

1

9

I'm using wkhtmltopdf v0.11.0 rc1 in a Rails application through wicked_pdf (I know wicked_pdf does not support the new command line parameter notation, I'm using my own fork of the gem). I thought that content not fitting within a page should automatically overflow to the next one, but this is not the case - I'm seeing text just being cut off, sometimes in the middle of a line.

I know I can layout my pages using page-break-after:always, but this looks like dirty hard-coding, and besides the HTML comes from an ERB template so it's not always obvious where to put page breaks.

Can something be done so that page breaks are inserted automatically? Am I missing something about how this works?

Here's what the generated command line looks like

\"c:/program files (x86)/wkhtmltopdf/wkhtmltopdf.exe\"
   --header-html \"file:///C:Users/bleak/AppData/Local/Temp/campaign_report.header.pdf_pdf_1580_0.html\" 
   --footer-html \"file:///C:/Users/bleak/AppData/Local/Temp/campaign_report.footer.pdf_pdf_1580_0.html\"
   --margin-top 20 --margin-bottom 15 --margin-left 5 --margin-right 40
   --page-size \"A4\"   
   page \"file:///C:/Users/bleak/AppData/Local/Temp/campaign_report_cover.pdf_pdf_1580_0.html\" --disable-javascript  
   toc --xsl-style-sheet \"c:/work/morizo/admoney/app/views/layouts/campaign_report.xsl\"  - - 
Irrigate answered 24/7, 2012 at 11:14 Comment(2)
Try removing the bottom margin, the margin is on the PDF, not the page generated so I think it's running into the margin and therefore you're seeing it cut off.Footing
Tried that. It makes no difference, the content is still cut off. I see I don't need the bottom margin though...Irrigate
I
16

It turned out that this was happening due to fixed sizes on divs used to wrap document sections:

div.page {
  width: 180mm;
  height: 277mm;
  overflow: hidden;
  page-break-after: always;
}

Once I removed width and height, auto breaking started working as expected. Simple.

Irrigate answered 24/7, 2012 at 13:15 Comment(3)
can you post the link to your wicked_pdf fork! It would be great to use it with 0.11.0 rc1Disassembly
@Irrigate Why 180mm and 277mm and not other numebers?Lactometer
This was a while ago so I'm no longer that clear on the details. My guess is that these numbers were initially tailored so that enough space was left for the header and footer.Irrigate

© 2022 - 2024 — McMap. All rights reserved.