1

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(); 
Nibra
  • 21
  • 3
  • If you could add a stamp to a PDF without invalidating the signature, what exactly would be the point of the signature in the first place? – David van Driessche Jun 25 '20 at 20:14
  • 1
    On non signed documents we add a layer with a little text to the PDF for long term archiving. But we cant do that on Signed PDF-s, thats why we need a solution. So after googling, a have read that its possible to add a stamp/annotation to the pdf that wont invalidate the signature, we did that but the annotation is not visible on browser(chrome mozilla edge) and cant be printed. But it works on Adobe Reader. – Nibra Jun 25 '20 at 21:23
  • 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 would be if you add your stamp as an image... – Lonzak Jun 26 '20 at 06:40

1 Answers1

0
  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(); 
Lonzak
  • 9,334
  • 5
  • 57
  • 88
  • Changing the page content (like adding an image there) is a sure way to make acrobat consider the signature broken. Read [here](https://stackoverflow.com/a/16711745/1729265) about allowed and disallowed changes. – mkl Jun 26 '20 at 07:25
  • 1
    Thank You #Lonzak. Thats what i needed. We will go with Image - transparent Image. – Nibra Jun 26 '20 at 09:31
  • @Nibra It is custom here to accept and/or upvote the answer if it was the correct solution for you. Welcome to Stackoverflow :-) – Lonzak Jun 30 '20 at 05:39
  • 1
    @Lonzak i tried, not only once. Got: Thanks for the feedback! Votes cast by those with less than 15 reputation are recorded, but do not change the publicly displayed post score. – Nibra Jun 30 '20 at 08:36
  • @Nibra There you go ;-) – Lonzak Jun 30 '20 at 12:24