this code:
- Code: Select all
// Layout the text
PdfStringLayouter textLayouter = new PdfStringLayouter();
PdfStringLayoutResult result = textLayouter.layout(getText(), // The text to be laid out
font, // The font to be used
format, // The formatting to be applied
pageSize // Constrain to page width
);
// Loop through each line of the laid-out text
for (LineInfo line : result.getLines()) {
// Draw each line of text
wrapper.getPage((float) font.measureString(line.getText()).getHeight()).getCanvas()
.drawString(line.getText(), // Text of the line
font, // Font to use
brush, // Brush for drawing
getX(wrapper.getPage()), wrapper.getY(), // x, y position
format, // Formatting
true);
if (line.getText().contains(FormUtils.INPUT_BOX_PLACEHOLDER)) {
FormUtils.addInlineInputBox(line.getText(), wrapper);
}
// Update y-coordinate for the next line
wrapper.incrementY(font.getSize() * PdfConfig.BODY_LINE_SPACING);
}
wrapper is a my utility class to hold the document.
when the text contain html tag (like in my case the <b>), the lines are break in the wrong way.
For example, a text block like: "<b>This is an example of a very long text just to show you the problem</b>: and the phrase continues without the bold"
is break into lines:
<b>This is an example of a very long text just to show you the
problem</b>: and the phrase continues without the bold
so I loose the bold formatting.