Some test text!

Hamburger Icon

Java / Guides / Add rectangle annotation

Add a rectangle annotation to a PDF in Java

To add a rectangle annotation to a PDF Document page.

PDFDoc doc = new PDFDoc(filename);
Page page = doc.getPage(1);

// Create a rectangle
Square sq = Square.create(doc, new Rect(500, 200, 580, 300));
sq.setColor(new ColorPt(1, 0, 0), 3);
sq.setInteriorColor(new ColorPt(0, 1, 1), 3);
double[] dash = {4, 2};
sq.setBorderStyle(new Annot.BorderStyle(Annot.BorderStyle.e_dashed, 6, 0, 0, dash));

Add or edit PDF annotations sample
Full code sample which shows how to add or edit PDF annotations (e.g. hyperlink, intra-document link, stamp, rubber stamp, file attachment, sound, text, free-text, line, circle, square, polygon, polyline, rectangle, squiggly, caret, and ink).

Get the answers you need: Chat with us