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

Free Support Forum - aspose.com

Creating Textbox annotation

Hi,

We are trying to create annotation on pdf as showing in the attached pdf using Aspose PDF for Jave. But could not achieve in the exact same format. Could you please let us know how can this be achieved using Aspose PDF for Java.out.pdf (262.3 KB)

@yalshaiba

Please try to add free text annotation using below code snippet that will look like the same in your shared PDF:

Document doc = new Document();
doc.getPages().add();
Rectangle rect = new Rectangle(0, 0, 100, 100);
DefaultAppearance appearance = new DefaultAppearance("Arial", 14, java.awt.Color.black);
FreeTextAnnotation freeTextAnnotation = new FreeTextAnnotation(doc.getPages().get_Item(1), rect, appearance);
freeTextAnnotation.setContents("text in the box");
freeTextAnnotation.setColor(Color.getRed());
freeTextAnnotation.getBorder().setWidth(2);
freeTextAnnotation.setFlags(AnnotationFlags.LockedContents);
doc.getPages().get_Item(1).getAnnotations().add(freeTextAnnotation);
doc.save(dataDir + "sampleoutput.pdf");

out_out.pdf (36.9 KB)
Thanks for the code snippet. This code generated the attached document and it did not look like the one which was requested. We are using Aspose PDF 21.5
Could you please check?

@yalshaiba

The output looks different due to specific properties being set in the share code snippet e.g. Color, Background, Border, Width, Rectangle Size, etc. You need to specify these options for annotation in order to make it look like your desired format.