1
gem 'wicked_pdf'
gem 'wkhtmltopdf-binary'

使用了以上两个宝石。但是当分页符时我收到文本剪切的问题。就像在屏幕截图中一样

在此处输入图像描述

我正在使用这段代码:-

  <%if current_company&.po_term.present?%>
    <div class="row po_term_condtions" style="page-break-before: always;">
      <div class="col-lg-12 col-md-12 col-sm-12" style="page-break-inside:avoid !important;">
        <strong> PO Terms: </strong>
        <%=current_company&.po_term&.po_description.html_safe%>
      </div>
    </div>
  <%end%>

但是我已经尝试了一些以前提出的问题的建议,但似乎不起作用

page-break-inside:avoid !important;
page-break-inside:avoid; display: inline; // display: block;

任何帮助,将不胜感激。

4

1 回答 1

0

您的文本似乎位于页脚下方,因此首先确保在调用 WickedPDF 时为页脚设置边距:

pdf = WickedPdf.new.pdf_from_string(
  html,
  margin: { top: 30, bottom: 30, left: 30, right: 30 },
  header: { content: html_header, spacing: 10 },
  footer: { content: html_footer, spacing: 10 }
)

您可能需要进行实验,我注意到wkhtmltopdf根据版本可能会产生不同的结果,而且我记得有些版本忽略了 css 分页符属性。

另外,如果您无法使用它:page-break-inside: avoid !important;那么您可以尝试page-break-before: always;

于 2018-04-27T05:14:02.777 回答