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.