繁体   English   中英

JTidy正在包装我的段落

[英]JTidy Is Wrapping My Paragraphs

我正在使用JTidy和Flying Saucer从HTML创建PDF文档。 在将文档传递到飞碟之前,我使用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);

但这并没有改变输出。 任何帮助,将不胜感激。

JTidy具有狭窄的默认包装边距大小。 为避免完全换行,请将wrap设置为0

tidy.setWraplen(0);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM