0

Now I need to add an additional picture information to PdfPage when signing.

The following are the desired results.

4 0 obj
<</Annots[11 0 R 19 0 R]/Contents[5 0 R 10 0 R 18 0 R]/MediaBox[0 0 595 842]/Parent 2 0 R/Resources<</Font<</F1 6 0 R>>/XObject<</Im1 9 0 R/Im2 17 0 R>>>>/TrimBox[0 0 595 842]/Type/Page>>

The "18 0 R" of "Contents[]" and the "/Im2 17 0 R" of XObject are the information inserted.By the following way.

        PdfCanvas canvas;
        canvas = new PdfCanvas(appearance.getLayer2(), document);
        appearance.getLocation();
        canvas.addImage(appearance.getSignatureGraphic(), imgWidth, 0, 0, imgHeight, appearance.getPageRect().getX(), appearance.getPageRect().getY());

        PdfPage pdfPage = document.getPage(1);
        PdfObject contents = ((PdfDictionary)pdfPage.getPdfObject()).get(PdfName.Contents);

        PdfArray array;
        if (contents instanceof PdfStream) {
            array = new PdfArray();
            array.add(contents);
            array.add(canvas.getContentStream());
            pdfPage.put(PdfName.Contents, array);
        } else if (contents instanceof PdfArray) {
            array = (PdfArray)contents;
            array.add(canvas.getContentStream());
        } else {
            array = null;
        }

        PdfImageXObject ax = new PdfImageXObject(appearance.getSignatureGraphic());
        ax.makeIndirect(document);
        PdfResources pdfResources = pdfPage.getResources();
        pdfResources.addImage(ax);

The picture was inserted, but the previous signature was also destroyed. How to insert pictures into PdfPage in the process of signature, but not affect the signature?

Thank you very much for your help.

张平启
  • 1
  • 1
  • Looking at your code, you're doing something that isn't allowed. Adding an image *after* a document is signed might be considered as fraud: you are *forging* the document. See the answer to the duplicate question to understand what is allowed and what isn't. Note: adding a *signature field* with an image should be possible, but that's a different question. If adding a signature field with an image in the signature appearance is what you want, please rephrase your question **and inform us about the nature of the initial signature** (maybe it's a "no changes allowed" signature). – Bruno Lowagie Aug 03 '18 at 09:53
  • Now the picture I signed can't be displayed on the iOS device, so I want to display it by covering a same picture. It was used because some of the electronic invoices could be displayed on the iOS, and I found that the PDF data was achieved through a picture covered method. – 张平启 Aug 03 '18 at 10:09
  • It would make me and many other developers and users extremely happy if you complained to Apple and made them implement the PAdES standard so that digital signatures can be consumed on Apple devices. It would be unfair if you blamed the software creating the signature if Apple doesn't want to comply with the standard. It would be dangerous if you'd push for a workaround that would open the door to signature fraud. Adding an image to a page of a signed PDF without invalidating the original signature should never be possible! – Bruno Lowagie Aug 03 '18 at 10:17
  • Thank you for your answer. I understand. I'll give feedback to BOSS. – 张平启 Aug 03 '18 at 11:51

0 Answers0