将html转换为pdf - 分页符拆分文本

问题描述 投票:5回答:4

我尝试使用pdflayer.com的api从HTML / CSS文档生成PDF文件。到现在为止还挺好。一切正常。但是有一个问题。如果有分页符,有时会像照片中那样分割一行:

split line

有没有办法摆脱这个问题?我也试过html2pdfrocket.com就是那个。

该文本放在这个html-construct中:

<html>
 <body>
  <div class="overall">
   <div class="content">
    <div class="wrapper">
     <div class="article">
      Text
html css pdf html2pdf html-to-pdf
4个回答
3
投票

我发现编译多个div内部的内容存在问题。 CSS规则不会影响问题的行为。

所以我有了一个想法,我所做的是生成一个“raw-html-output”。在这个HTML文档中只有

<html>
 <head>
  <style>
   The only necessary css-rules.
  </style>
 </head>
 <body>
  Some text here.
 </body>
</html>

而已。

API从简化的html文件中获取数据并编译好。


0
投票

如果你使用firefox,用它打开html doc并安装名为PDF Mage的附加组件。只需单击图标即可将页面转换为PDF。它总是对我没有任何问题。

最好的问候


0
投票

我认为最好的解决方案是防止打印段落内。像这样的东西:

@media print and (min-width:700px) {
    /* you can change the selector to whatever you need */
    .article {
        break-inside: avoid;
        page-break-inside: avoid;
    }
}

0
投票

您可以尝试使用Syncfusion在线demo将HTML转换为PDF。我们正在处理跨页面分割的文本和图像。

注意:我为Syncfusion工作。

© www.soinside.com 2019 - 2024. All rights reserved.