Automatic page breaks wkhtmltopdf

I use wkhtmltopdf v0.11.0 rc1 in a Rails application via wicked_pdf (I know that wicked_pdf does not support the new command line parameter notation, I use my own gem fork). I thought that content that is not appropriate inside the page should automatically go to the next, but it’s not - I see that the text is simply cut off, sometimes in the middle of the line.

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

Is there anything you can do to get page breaks inserted automatically? Am I missing something about how this works?

This creates the generated command line

 \"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\" - - 
+6
source share
1 answer

It turned out that this was due to the fixed sizes on the div used to wrap sections of the document:

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

As soon as I removed the width and height , the automatic splitting started working as expected. Plain.

+13
source

Source: https://habr.com/ru/post/921194/


All Articles