We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Text Wrapping does not allow top to bottom approach (Aspose Pdf Java)

I want the text to wrap from top to bottom how the ByWords wrapping option starts the paragraph from bottom left. Kindly guide how can i start the paragraph from top left. Here is the code that i am using:

Page page = doc.getPages().get_Item(1);
TextBuilder builder = new TextBuilder(page);
TextParagraph paragraph = new TextParagraph();
paragraph.setSubsequentLinesIndent (20);
paragraph.setRectangle(new Rectangle(90, 370, 520, 950));
paragraph.setBackgroundColor(Color.getYellow());
paragraph.getFormattingOptions().setWrapMode(TextFormattingOptions.WordWrapMode.ByWords);
TextFragment fragment1 = new TextFragment(desc);
fragment1.getTextState().setFontSize (12);
paragraph.appendLine(fragment1);
builder.appendParagraph(paragraph);

image.png (29.8 KB)

I want to fit a text box in Document notes that starts from above but current code starts the text from bottom left.

@ahmedtariq

The Aspose.PDF and PDF documents follow the coordinating system which starts from bottom-left. In case you want to add text starting from top-left corner, you can use the TextFragment Class. Please share your sample source and expected output PDF documents in case you are still unable to get the desired output. We will further proceed to assist you accordingly.

Can you guide how can i build a paragraph using TextFragment class? I have a Rectangle in which i want my text to fit starting from the top-left corner.
Thanks

@ahmedtariq

Do you have coordinates of that rectangle as well? Can you please share your sample source PDF file as requested earlier? We will check it and try to produce a code sample to achieve your requirements and share our feedback with you.