我正在使用 JTidy 和 Flying Saucer 从 HTML 创建 PDF 文档。在将文档传递到 Flying Saucer 之前,我使用 JTidy 确保所有元素都干净且格式正确。
我遇到了一个我无法弄清楚的 JTidy 问题。有一个“p”元素包含大量文本,它是从数据库中填充的,并已使用空格进行格式化。在 HTML 中,它使用样式“white-space: pre-line;”显示。所以它显示了这样的东西
<p>
Section 1:
A lot of text from section 1 that goes on and on for quite some time.
Section 2 :
....
</p>
这在浏览器中正确显示,我们根据它们的空格划分了部分。然而,通过 JTidy 运行后,上面的代码变成了
<p> Section 1: A lot of text from section 1
that goes on and on for quite some time.
Section 2 : ....
</p>
本质上,它只是将所有文本包装成一个大部分,该部分仅适用于一定数量的字符,然后换行到下一行。因此,由于我使用的是预行,因此生成的 PDF 中的输出是错误的。我查看了http://jtidy.sourceforge.net/apidocs/org/w3c/tidy/Tidy.html上的文档,但找不到解决方案。到目前为止,我的 Java 代码看起来像这样
Tidy tidy = new Tidy();
tidy.setShowWarnings(true);
tidy.setInputEncoding("UTF-8");
tidy.setOutputEncoding("UTF-8");
tidy.setXHTML(true);
tidy.setMakeClean(true);
我试过使用
tidy.setWrapSection(false);
但这并没有改变输出。任何帮助,将不胜感激。