Skip to main content
Skip table of contents

How to modify the size of annotations and make them read-only?

1. Is it possible to disable the options dropdown list for annotations(text,stamp etc.)? If so, how? 2. Can the size of the annotation boxes (for popup annotations, text annotations, etc.) be changed?

I have a requirement to make the annotations content read-only, to disable the options, and to change their size.

I want to disable these drop-down options:

Drop-down options

Posted on StackOverflow on Nov 9, 2015 by Harshit Pant

You can't prevent that people use the drop-down list, but you can make sure that functionality such as "Reply" and "Delete" isn't shown in that list by encrypting the document using an owner password, making sure that you don't set the option that allows people to add annotations. Once the PDF is encrypted, you'll notice that the entries in the drop-down list are limited. (See How to decrypt a PDF document with the owner password? to learn more about encryption.)

Changing the size of an annotation is a matter of replacing the PDF rectangle that was defined for that annotation. Please take a look at the MovePopup example.

We have the following annotation and popup:

Text / popup annotation

Incidentally, I know that the text annotation is the first annotation in the /Annots array and that the popup is the second one. In iText 7 we use getAnnotations() method to manipulate the annotations:

public void manipulatePdf(String src, String dest) throws Exception {
    PdfDocument pdfDoc = new PdfDocument(new PdfReader(src), new PdfWriter(dest));
    Document doc = new Document(pdfDoc);

    List list = pdfDoc.getFirstPage().getAnnotations();

    PdfAnnotation stickyAnnot = list.get(0);
    PdfArray stickyRect = stickyAnnot.getRectangle();
    PdfArray stickyRectangle = new PdfArray(new float[]{
            stickyRect.getAsNumber(0).floatValue() - 120, stickyRect.getAsNumber(1).floatValue() - 70,
            stickyRect.getAsNumber(2).floatValue(), stickyRect.getAsNumber(3).floatValue() - 30
    });
    stickyAnnot.setRectangle(stickyRectangle);

    PdfAnnotation popupAnnot = list.get(1);
    PdfArray popupRect = popupAnnot.getRectangle();
    PdfArray popupRectangle = new PdfArray(new float[]{
            popupRect.getAsNumber(0).floatValue() - 250, popupRect.getAsNumber(1).floatValue(),
            popupRect.getAsNumber(2).floatValue(), popupRect.getAsNumber(3).floatValue() - 250
    });
    popupAnnot.setRectangle(popupRectangle);

    doc.close();
}

I have made both rectangles bigger by subtracting 120, 70, 250,... user units from the x and y values in the /Rect value (get- and setRectangle() methods of the PdfAnnotation class) of the annotations here and there.

The result looks like this:

Text / popup annotation moved / resized

Both the text annotation icon and the actual popup with the text are now bigger.

It is up to you to adapt the code, so that:

  1. You find the actual popup annotation that you want to enlarge,

  2. You change the rectangle of that annotation with the amount of user units of your choice.

Click How to modify the size of annotations and make them read-only? if you want to see how to answer this question in iText 5.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.