LibrePDF / OpenPDF

OpenPDF is a free Java library for creating and editing PDF files, with a LGPL and MPL open source license. OpenPDF is based on a fork of iText. We welcome contributions from other developers. Please feel free to submit pull-requests and bugreports to this GitHub repository.
Other
3.55k stars 585 forks source link

showText isn't creating new lines if string is bigger than pdf width #736

Open TarunNanduri opened 2 years ago

TarunNanduri commented 2 years ago

Describe the bug showText isn't creating new lines if string is bigger than pdf width

To Reproduce Code to reproduce the issue

String s1 = "OpenPDF is open source software with a LGPL and MPL license. It is a fork of iText version 4, more specifically iText svn tag 4.2.0, which was hosted publicly on sourceforge with LGPL and MPL license headers in the source code, and LGPL and MPL license documents in the svn repository. Beginning with version 5.0 of iText, the developers have moved to the AGPL to improve their ability to sell commercial licenses.";
contentByte.setFontAndSize(BaseFont.createFont(fontFileName, BaseFont.IDENTITY_H, false), fontSize);
contentByte.beginText();
contentByte.beginMarkedContentSequence(new PdfStructureElement(element2, PdfName.P));
contentByte.setTextMatrix(document.leftMargin(), 600);
contentByte.showText(s1);
contentByte.endMarkedContentSequence();
contentByte.endText();

Expected behavior I expect string to move to next line if page-end is hit.

Screenshots image

System (please complete the following information):

Additional context Add any other context about the problem here.

TarunNanduri commented 2 years ago

This holds true, even if I use an LayoutProcessor supported font.

youyumeimei commented 2 years ago

Hello @TarunNanduri , our group are interested in this issue, and we will try to fix it. ---- SE_SUSTech, group: Lanrand

TarunNanduri commented 2 years ago

Great, Looking forward!

vk-github18 commented 7 months ago

Dont't use the low-level API directly. See e.g. https://github.com/LibrePDF/OpenPDF/wiki/Paragraphs