Java iText PDF annotation/stamp not visible on Chrome and Firefox (browsers)

1k Views Asked by At

We have been trying to add annotation/stamp to an existing SIGNED PDF without invalidating the Signature but unfortunately browsers wont show the stamp/annotation. When opened in Adobe Reader the annotation can be seen there. Any other idea is welcome. All we want is a little text on existing signed PDF that wont invalidate the signature.

Here is our code:

    PdfReader reader = new PdfReader(pdf1);
    PdfStamper pdfStamper = new PdfStamper(reader, new FileOutputStream(RESULT), '\0', true);
    PdfContentByte pcb = new PdfContentByte(pdfStamper.getWriter());
    PdfAnnotation annot = PdfAnnotation.createFreeText(pdfStamper.getWriter(),  new Rectangle(150, 150, 200, 200), "Annotation 1", pcb);
    annot.setFlags(PdfAnnotation.FLAGS_PRINT);
    pdfStamper.addAnnotation(annot, 1);
    pdfStamper.close(); 
1

There are 1 best solutions below

5
Lonzak On
  1. You use the incremental update mode ('\0', true) thus (certain) additions to PDF documents are possible. That is the correct way
  2. WebBrowsers provide only limited support for certain PDF features like Formfields or annotions. If you can see the annotation in the adobe reader but not in some webbrowers than those browsers do not support it. You have limited options to change that.

One possibility you might have is to not add the stamp as an annotation but as an image. But you have to test afterwards if acrobat reader still considers the signature as intact. (As mentioned only certain additions are allowed)

PdfReader reader = new PdfReader(pdf1);
    PdfStamper pdfStamper = new PdfStamper(reader, new FileOutputStream(RESULT), '\0', true);
    Image img = Image.getInstance("URL or Filename.PathToImage.png");
    //position on the page x,y
    img.setAbsolutePosition(380f, 750f);
    img.scalePercent(20);
    //1=pagenumber and you might also try getOverContent(1)
    PdfContentByte underContent = super.stamper.getUnderContent(1);
    underContent.addImage(img);        

    pdfStamper.close();