问题
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\" - -
回答1:
It turned out that this was happening due to fixed sizes on div
s 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.
来源:https://stackoverflow.com/questions/11629661/wkhtmltopdf-automatic-page-breaks