简体   繁体   English

JTidy正在包装我的段落

[英]JTidy Is Wrapping My Paragraphs

I am using JTidy and Flying Saucer to create PDF documents from HTML. 我正在使用JTidy和Flying Saucer从HTML创建PDF文档。 I use JTidy to make sure all the elements are clean and formatted correctly before passing the document into Flying Saucer. 在将文档传递到飞碟之前,我使用JTidy来确保所有元素都是干净的并且格式正确。

I have run into an issue with JTidy that I cannot figure out. 我遇到了JTidy的问题,无法解决。 There is one "p" element that has quite a lot of text, it is being populated from a database and has been formatted using white spaces. 有一个“ p”元素,其中包含大量文本,它是从数据库中填充的,并已使用空格格式化。 In the HTML it is displayed using the style "white-space: pre-line;" 在HTML中,它使用样式“ white-space:pre-line;”显示。 and so it shows up something like this 所以它显示出这样的内容

<p>
Section 1:
A lot of text from section 1 that goes on and on for quite some time.

Section 2 :
....
</p>

This is displayed correctly in the browser where we have section broken out based on their whitespace. 这会在浏览器中正确显示,我们在其中根据其空格将其细分。 However after running through JTidy the above code turns into 但是,在运行了JTidy之后,上面的代码变成了

<p>  Section 1: A lot of text from section 1 
that goes on and on for quite some time.
Section 2 : ....
</p>

Essentially it just wraps all the text into a big section that only goes for a certain number of characters and then wraps to the next line. 本质上,它只是将所有文本包装到一个大的部分中,该部分只包含一定数量的字符,然后包装到下一行。 Because of this, since I am using pre-line the output in the resulting PDF is wrong. 因此,由于我使用的是预行,因此生成的PDF中的输出是错误的。 I have looked into the documentation at http://jtidy.sourceforge.net/apidocs/org/w3c/tidy/Tidy.html but haven't been able to find the solution. 我已经浏览了http://jtidy.sourceforge.net/apidocs/org/w3c/tidy/Tidy.html上的文档,但是找不到解决方案。 So far my Java code looks like this 到目前为止,我的Java代码看起来像这样

Tidy tidy = new Tidy();
tidy.setShowWarnings(true);
tidy.setInputEncoding("UTF-8");
tidy.setOutputEncoding("UTF-8");
tidy.setXHTML(true);
tidy.setMakeClean(true);

I have tried using 我尝试使用

tidy.setWrapSection(false);

but this has not changed the output. 但这并没有改变输出。 Any help would be appreciated. 任何帮助,将不胜感激。

JTidy has a narrow default wrap margin size. JTidy具有狭窄的默认包装边距大小。 To avoid wrap altogether set wrap to 0 为避免完全换行,请将wrap设置为0

tidy.setWraplen(0);

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

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