1

I have a requirement to make the Annotations' content uneditable and disable the options. SO,

1. Is it possible to disable the options dropdown list for PdfAnnotation objects(text,stamp etc.) in iText.If yes, then How??
2. Also can the size of the annotation boxes(for Popup, text etc.) be changed? The text in annotations has been made uneditable by using this PdfAnnotation.FLAGS_READONLY

how to disable the dropdown options here https://i.stack.imgur.com/5QmGj.jpg

  • Did my answer solve the problem? I didn't see any activity on it: no comments, no up-vote, no down-vote, not accepted yet... – Bruno Lowagie Nov 18 '15 at 15:46

1 Answers1

0

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 protect an already existing PDF with a password? to find out how to encrypt a document.)

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:

enter image description here

Incidentally, I know that the text annotation is the first annotation in the /Annots array and that the popup is the second one. This means that I can cut some corners in my code:

public void manipulatePdf(String src, String dest) throws IOException, DocumentException {
    PdfReader reader = new PdfReader(src);
    PdfDictionary page = reader.getPageN(1);
    PdfArray annots = page.getAsArray(PdfName.ANNOTS);
    PdfDictionary sticky = annots.getAsDict(0);
    PdfArray stickyRect = sticky.getAsArray(PdfName.RECT);
    PdfRectangle stickyRectangle = new PdfRectangle(
        stickyRect.getAsNumber(0).floatValue() - 120, stickyRect.getAsNumber(1).floatValue() -70,
        stickyRect.getAsNumber(2).floatValue(), stickyRect.getAsNumber(3).floatValue() - 30
    );
    sticky.put(PdfName.RECT, stickyRectangle);
    PdfDictionary popup = annots.getAsDict(1);
    PdfArray popupRect = popup.getAsArray(PdfName.RECT);
    PdfRectangle popupRectangle = new PdfRectangle(
        popupRect.getAsNumber(0).floatValue() - 250, popupRect.getAsNumber(1).floatValue(),
        popupRect.getAsNumber(2).floatValue(), popupRect.getAsNumber(3).floatValue() - 250
    );
    popup.put(PdfName.RECT, popupRectangle);
    PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));
    stamper.close();
}

I have made both rectangles bigger by subtracting 120, 70, 250,... user units from the x and y values in the /Rect value of the annotations here and there.

The result looks like this:

enter image description here

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.
Community
  • 1
  • 1
Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165
  • using the manipulatePdf() throws Null Pointer Exception. The annots is getting initialized as null and the page.getAsArray(PdfName.ANNOTS); throws the Exception. Why is that or What to do? – Harshit Pant Nov 23 '15 at 06:52
  • If `getAsArray(PdfName.ANNOTS)` returns `null, then there are no annotations on your page. It's as simple as that. – Bruno Lowagie Nov 23 '15 at 06:53