Remove Unsigned Signature Field

Product: PDFTron C# Sdk

Product Version: 8.1

Please give a brief summary of your issue:
After Removing Existing Digital Signature, Field is Listed as Unsigned Signature Field.

Please describe your issue and provide steps to reproduce it:

  1. Digitally sign pdf document;

  2. Clear signature on step 1 by C# code:

         using var fieldIterator = pdfToSign.GetDigitalSignatureFieldIterator();
         if (fieldIterator.HasNext()) {
             firstPage.AnnotRemove(0);                
             using var field = fieldIterator.Current();
             field.ClearSignature();
         }
    
  3. Sign with other signature:

         var digitalSignatureField = pdfToSign.CreateDigitalSignatureField(integrityMessage);
         var signatureWidget = SignatureWidget.Create(pdfToSign, new Rect(0, 0, 0, 0), digitalSignatureField);
         signatureWidget.SetFlag(Annot.Flag.e_no_view, true);
         firstPage.AnnotInsert(IntegritySignaturePosition, signatureWidget);
    
         digitalSignatureField.SetDocumentPermissions(DigitalSignatureField.DocumentPermissions.e_no_changes_allowed);
         digitalSignatureField.SignOnNextSave(systemOptions.KeyFilePath, systemOptions.KeyFilePassword);
    
  4. After saving see empty digital signature in Unsigned Signature Field: test-fca6f65d-abff-4d10-a8f0-812c5364f247.pdf (102.7 KB)

  5. Could not find way to remove unsigned signature field. Tried followings: How to delete a specific digital signature field?

Please provide a link to a minimal sample where the issue is reproducible:

Hello, I’m Ron, an automated tech support bot :robot:

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:

Guides:APIs:Forums:

Hello,

This should be the order (to avoid your error):

  1. Completely remove field and annotation using this code:
    How to delete a specific digital signature field?

  2. Sign

To investigate further could you please provide the following information.

  1. Input file(s)

  2. Generated output file(s)

  3. Complete code and settings used to generate (2) from (1)

  4. Screenshots showing the output, and clearly indicating what you expected to get instead, and also clearly indicating the application/browser being used to view.

Hi! Joe,

Thank you for you link, we have already tried that link.

We want to achieve integrity after user signature. Multiple users may sign. Signatures maybe just wet signature, not digital signatures.

We want to guarantee that file not changed after download, that is why we put our own digital signature.
But we don not want to put own digital signature after every user wet signature. So we remove our old digital signature and sign again.

  1. Input file test.pdf (34.3 KB)

  2. Output file test-e2a7e37a-f042-4687-ba28-fd3852bef8ec.pdf (44.4 KB)

  3. Code:

     public MemoryStream Sign(Stream documentStream, IEnumerable<WetSignatureInfo> signatureInfos, string integrityMessage)
     {
         var pdfToSign = new PDFDoc(documentStream);
    
         
         foreach (var (signatureProperties, signatureStream) in signatureInfos) {
             using var signatureImage = Image.Create(pdfToSign, signatureStream);
             var (sigPage, sigX, sigY, sigWidth, sigHeight) = signatureProperties;
             
             using var stamper = new Stamper(Stamper.SizeType.e_absolute_size, sigWidth, sigHeight);
             stamper.SetAlignment(Stamper.HorizontalAlignment.e_horizontal_left, Stamper.VerticalAlignment.e_vertical_top);
             stamper.SetAsAnnotation(true);
             stamper.SetAsBackground(false);
             stamper.SetSize(Stamper.SizeType.e_absolute_size, sigWidth, sigHeight);
             stamper.SetPosition(sigX, sigY);
             stamper.StampImage(pdfToSign, signatureImage, new PageSet(sigPage));
         }
    
         var firstPage = pdfToSign.FirstPage();
         using var dsFieldIterator = pdfToSign.GetDigitalSignatureFieldIterator();
         while (dsFieldIterator.HasNext()) {
             using var dsField = dsFieldIterator.Current();
             firstPage.AnnotRemove(IntegritySignaturePosition);
             dsField.ClearSignature();
             break;
         }
         
         var digitalSignatureField = pdfToSign.CreateDigitalSignatureField(integrityMessage);
    
         var signatureWidget = SignatureWidget.Create(pdfToSign, new Rect(0, 0, 0, 0), digitalSignatureField);
         signatureWidget.SetFlag(Annot.Flag.e_no_view, true);
         firstPage.AnnotInsert(IntegritySignaturePosition, signatureWidget);
    
         digitalSignatureField.SetDocumentPermissions(DigitalSignatureField.DocumentPermissions.e_annotating_formfilling_signing_allowed);
         // digitalSignatureField.SetFieldPermissions(DigitalSignatureField.FieldPermissions.e_lock_all);
         digitalSignatureField.SignOnNextSave(systemOptions.KeyFilePath, systemOptions.KeyFilePassword);
    
         return SavePdfDocumentToMemory(pdfToSign, SDFDoc.SaveOptions.e_incremental);
     }
    
     private const int IntegritySignaturePosition = 0;
  1. Screenshot Adobe Acrobat Reader DC, Version: 21.007.20091.59174 is used on Ubuntu 20.04

Hello,

I want to clarify on your use case below:

Typically, the best way to make sure that the document has not been tampered with is to add an approval signature each time the document has been signed, so that it is guaranteed that only authorized people re modifying the document. Note that to do this, all fields must be present before any signature is added.

Could you please confirm if this is what you are looking to do?

Hi Shakhi,

Yes, that is our goal. But we wanted put approval signature for document after each e-signature (wet signature). So we wanted remove old digital (approval) signature and sign again after each wet signature. This was needed for: 1) Document was given by our system, 2) Document has not altered since.

We have solved problem, just by redoing wet-signatures from beginning and putting one approval digital signature.

Thank you for your help.
Munduz