I am using JTidy and Flying Saucer to create PDF documents from HTML. I use JTidy to make sure all the elements are clean and formatted correctly before passing the document into Flying Saucer.
I have run into an issue with JTidy that I cannot figure out. 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. In the HTML it is displayed using the style "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
<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. 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. So far my Java code looks like this
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. To avoid wrap altogether set wrap to 0
tidy.setWraplen(0);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.