Fixing the leading problem
When no content has been added to a Document
, the initial leading is 0.
As soon as a Paragraph
is added to the Document
, the default leading changes into the leading of that Paragraph
.
In our first example, we started by adding a Chunk
object, and all of its content was written on the first line because the initial leading is 0.
We can avoid this problem by setting an initial leading. In the next example, we set the initial leading to 12.5 point.
Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("results/xmlworker/walden2.pdf")); writer.setInitialLeading(12.5f); document.open(); XMLWorkerHelper.getInstance().parseXHtml(writer, document, HTMLParsingDefault2.class.getResourceAsStream("/html/walden.html"), null); document.close();
see HTMLParsingDefault2 and the resulting PDF walden2.pdf
The content inside the <pre>
tags in the HTML file is now legible in the PDF.