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

Free Support Forum - aspose.com

Multiline TextStamp Justify text alignment not working

Hi,


text stamp setTextAlignment() seems to be ignore for HorizontalAlignment.Justify & HorizontalAlignment.FullJustify values.

Try this code sample:
public static void main(String[] args) {
String stampText = “Stamp text with\nmultiple lines\nthat are not aligned”;
List stamps = new ArrayList<>();
stamps.add(createTextStamp(stampText, HorizontalAlignment.Left, VerticalAlignment.Top, HorizontalAlignment.Left));
stamps.add(createTextStamp(stampText, HorizontalAlignment.Center, VerticalAlignment.Top, HorizontalAlignment.Center));
stamps.add(createTextStamp(stampText, HorizontalAlignment.Right, VerticalAlignment.Top, HorizontalAlignment.Right));
stamps.add(createTextStamp(stampText, HorizontalAlignment.Left, VerticalAlignment.Center, HorizontalAlignment.Justify));
stamps.add(createTextStamp(stampText, HorizontalAlignment.Center, VerticalAlignment.Center, HorizontalAlignment.FullJustify));
// open document
Document pdfDocument = new Document(“d:\temp\input.pdf”);
for (int Page_counter = 1; Page_counter <= pdfDocument.getPages().size(); Page_counter++) {
// add stamp to all pages of PDF file
for (TextStamp stamp : stamps) {
pdfDocument.getPages().get_Item(Page_counter).addStamp(stamp);
}
}
pdfDocument.save(“d:\temp\TextStamp_output.pdf”);
}

private static TextStamp createTextStamp(String text, int hAlign, int vAlign, int tAlign) {
final FormattedText stampText = new FormattedText();
new BufferedReader(new StringReader(text))
.lines().forEach(l -> stampText.addNewLineText(l));
TextStamp textStamp = new TextStamp(stampText);
textStamp.setHorizontalAlignment(hAlign);
textStamp.setVerticalAlignment(vAlign);
textStamp.setTextAlignment(tAlign);

return textStamp;
}

Thanks.

Hi There,


Thanks for contacting support.

I have tested the entire scenario in my environment and was able to reproduce the issue. Therefore for the sake of correction, I have logged it as PDFJAVA-36663 in our issue tracking system. We will further look into the details of the issue and keep you informed on the status of its resolution. Please be patient and spare us a little time.

We are sorry for the inconvenience.


Best Regards,