1

I have attached an image into a signed pdf document using itext7, but the signature became invalid. Is there any solution for this

string source = @"D:\SampleProjects\itext\file\test.pdf";
string target = @"D:\SampleProjects\itext\file\tests.pdf";
string img = @"D:\SampleProjects\itext\file\sign_valid.png";

PdfDocument pdfDocument = new PdfDocument(new PdfReader(source), new PdfWriter(target));

// Document to add layout elements: paragraphs, images etc
Document document = new Document(pdfDocument);
var noofpages = pdfDocument.GetNumberOfPages();

// Load image from disk
ImageData imageData = ImageDataFactory.Create(img);

// Create layout image object and provide parameters. Page number = 1
Image image = new Image(imageData).ScaleAbsolute(100, 100).SetFixedPosition(1, 25, 25);

document.Add(image);
document.Close();
Christian Baumann
  • 3,188
  • 3
  • 20
  • 37
Safvan AK
  • 11
  • 2
  • 1
    The point of the signature is to detect changes to the document after it has been signed. And that's what you did. The only solution to this is: Sign it again. If cannot, then you shouldn't change the document. – Fildor Oct 15 '20 at 08:52
  • First of all, when working with signed pdfs, you have to use *append* mode to not invalidate the original signatures. Furthermore, you have to respect the changes allowed by the existing signatures. In particular changing the static page content never is allowed. But what may be allowed is adding annotations. Thus, you should try adding new annotations with your image. – mkl Oct 15 '20 at 13:22
  • @mkl I have tried in that way but still getting invalid – Safvan AK Oct 16 '20 at 04:32
  • Please share an example PDF and image to reproduce the issue. – mkl Sep 17 '21 at 14:31

1 Answers1

1

It's a feature that the signature becomes invalid when the document is changed.

So I would say the answer to your question is no.

I recommend you attach the image before the document is signed.

Niels Brinch
  • 3,033
  • 9
  • 48
  • 75
  • In case of integrated PDF signatures the situation is different if changes are applied as incremental updates. Here changes to the document are appended to it, so the signature still correctly signs the original revision. Nonetheless, only very specific changes are allowed, see [this answer](https://stackoverflow.com/a/16711745/1729265). – mkl Oct 16 '20 at 10:01