You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Frédéric Ravetier <fr...@vikta.com> on 2023/04/12 14:56:29 UTC

Text annotation using multiline

Hi,

Is it possible to add an annotation that contains text, for example "This
is a very long string and I want to display this string in a multiline
annotation", and I want to define a box of 150 pixels width. So then the
text displaying on  multiple lines.

At this time I am using

PDAnnotationRubberStamp stamp = new PDAnnotationRubberStamp();

...

PDRectangle rect = new PDRectangle(viktaAnnotation.getX(), ph -
annotation.getY() - heightTranslate, objectWidth, objectHeight);
stamp.setRectangle(rect);


PDAppearanceStream appearanceStream = new PDAppearanceStream(doc);

...

appearanceStream.setBBox(new PDRectangle(150, 200));

...

contentStream.beginText();
contentStream.setTextMatrix(Matrix.getTranslateInstance(0, heightTranslate));
contentStream.showText("This is a very long string and I want to
display this string in a multiline annotation");
contentStream.endText();

...

PDAppearanceDictionary appearance = new PDAppearanceDictionary();
appearance.setNormalAppearance(appearanceStream);
stamp.setAppearance(appearance);
stamp.setIntent(PDAnnotationRubberStamp.IT_FREE_TEXT);

annotations.add(stamp);
page.setAnnotations(annotations);



Best regards,
Fred