Paragraph Line Wrap - How to wrap downwards?

I have dynamic content I’m adding to a newly created PDF that needs to line wrap downwards, similar to how HTML is wrapped in a browser. However, because paragraph positioning uses the lower left corner, when a line wraps it pushes the rest of the paragraph upwards.

Current code:
final TextParagraph paragraph = new TextParagraph();
paragraph.getFormattingOptions().setWrapMode(1);
paragraph.setRectangle(new Rectangle(135, 500, 560, 600));
paragraph.appendLine(“LOTS OF TEXT…”);
textBuilder.appendParagraph(paragraph);

How can I specify where a paragraph begins (rather than ends), and have it wrap downwards?

Hi there,


Thanks for your your inquiry. I have tested your shared code and unable to notice the reported issue. I will appreciate it if you please share complete code and output, so we will look into it and guide you accordingly.

Document pdfDocument = new Document(myDir+“HelloWorld.pdf”);<o:p></o:p>

//get particular page

Page pdfPage = pdfDocument.getPages().get_Item(1);

//create TextBuilder object

TextBuilder textBuilder = new TextBuilder(pdfPage);

final TextParagraph paragraph = new TextParagraph();

paragraph.getFormattingOptions().setWrapMode(1);

paragraph.setRectangle(new Rectangle(135, 500, 560, 600));

paragraph.appendLine("Electronic Supporting Information files are available without a subscription to \r\nACS Web Edit ions. The American Chemical Society \r\nholds a copyright ownership interest in any copyrightable Supporting Information. Files available from the ACS website may be");

textBuilder.appendParagraph(paragraph);

////save output file

pdfDocument.save(myDir+"LineBreak_output.pdf");

We are sorry for the inconvenience caused.

Best Regards,

My problem is related to variable length inputs. I do not want to manually specify new lines using "\r\n". The purpose of using the line wrap is so the new lines are created at the correct location in the input string. Attached are 2 files. 'shortText' shows the behavior for a short input string. 'longText' shows the behavior for a long input string. Compare the 2 pdfs side by side. Notice how the bottom of the paragraphs are aligned, and the length of the input determines where the top of the paragraph is located. I need to have the tops of the paragraphs in a fixed location, and have the text wrap dynamically afterwards.


Here is the code:


String variableLengthInputString = "variable length string without newlines (no \\n or \\r)";

Document pdfDocument = new Document(myDir+"HelloWorld.pdf");

//get particular page

Page pdfPage =
pdfDocument.getPages().get_Item(1);
//create TextBuilder object
TextBuilder textBuilder = new
TextBuilder(pdfPage);

final TextParagraph section3_1 = new TextParagraph();
section3_1.getFormattingOptions().setWrapMode(2);
section3_1.setRectangle(new Rectangle(135, 500, 560, 600));
section3_1.appendLine(variableLengthInputString);
textBuilder.appendParagraph(section3_1);

////save output file
pdfDocument.save(myDir+“LineBreak_output.pdf”);

Hi there,

Thanks for sharing additional information. I have noticed the paragraph wrapping issue and logged an issue in our issue tracking system as PDFNEWJAVA-35213 for further investigation and rectification. We will keep you updated via this thread regarding the issue status.

We are sorry for the inconvenience caused.

<span style=“font-size:10.0pt;line-height:115%;font-family:“Arial”,“sans-serif”;
mso-fareast-font-family:Calibri;color:#333333;mso-ansi-language:EN-US;
mso-fareast-language:EN-US;mso-bidi-language:AR-SA”>Best Regards,

How may I view the status and updates on this ticket? When can I expect a response, either for a work around or a full solution?

Hi Kyle,


Thanks for your patience.

As we recently have noticed this, so product team requires little time to investigate and figure out the actual reasons behind this problem. As soon as we have some definite updates, we will let you know.