wkhtmltopdf自动分页符 [英] wkhtmltopdf automatic page breaks

查看:1329
本文介绍了wkhtmltopdf自动分页符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过wicked_pdf在Rails应用程序中使用wkhtmltopdf v0.11.0 rc1(我知道wicked_pdf不支持新的命令行参数符号,我使用的是自己的gem分支).我认为不适合页面的内容会自动溢出到下一页,但事实并非如此-我看到的是文本被截断,有时在一行的中间.

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.

我知道我可以使用page-break-after:always来布局页面,但这看起来像是肮脏的硬编码,而且HTML来自ERB模板,因此在何处放置分页符并不总是很明显.

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\"  - - 

推荐答案

事实证明,发生这种情况是由于用于包装文档部分的div的固定大小所致:

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;
}

一旦我删除了widthheight,自动中断就会按预期开始工作.很简单.

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

这篇关于wkhtmltopdf自动分页符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆