wkhtmltopdf automatic page breaks

烈酒焚心 提交于 2019-12-07 01:03:19

问题


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 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.



来源:https://stackoverflow.com/questions/11629661/wkhtmltopdf-automatic-page-breaks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!