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.