Skip to main content
Skip table of contents

Changing properties of an annotation

Examples in answer to questions such as:



 * This example was written by Bruno Lowagie in answer to the following question:
package sandbox.annotations;

import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.PdfArray;
import com.itextpdf.text.pdf.PdfDictionary;
import com.itextpdf.text.pdf.PdfName;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfRectangle;
import com.itextpdf.text.pdf.PdfStamper;
import sandbox.WrapToTest;

 * @author iText
public class MovePopup {
    public static final String SRC = "resources/pdfs/hello_sticky_note.pdf";
    public static final String DEST = "results/annotations/hello_sticky_moved.pdf";

    public static void main(String[] args) throws IOException, DocumentException {
        File file = new File(DEST);
        new MovePopup().manipulatePdf(SRC, DEST);
    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));

JavaScript errors detected

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

If this problem persists, please contact our support.