Iterative Digital signing of the PDF document

GroupDocs.Signatureย providesย DigitalSignOptionsย classย to specify different amount of settings for Digital signature

Here are the steps to add Digital signature into document with GroupDocs.Signature:

  • Define the paths for the input PDF file, the digital certificates, and specify the output path where the signed documents will be saved.
  • Create a new instance of theย Signatureย class and pass the source document path as a constructor parameter.
  • Instantiate theย DigitalSignOptionsย object with the required certificate and its password, and configure additional properties such as reason, contact, location, and position.
  • Call theย Signย method ofย Signatureย class instance and passย DigitalSignOptionsย to it.
  • After signing, update the document path for the next iteration.
  • Analyze theย SignResultย to check the newly created signatures if needed.
  • Iterate through each certificate, repeating the above steps for each one.

This example demonstrates how to iteratively sign a PDF document with multiple digital certificates.ย Seeย SignResult

string filePath = "sample.pdf";
string fileName = Path.GetFileName(filePath);

string[] certificatePaths = new string[] { "certificate1.pfx", "certificate2.pfx" };

string outputFilePath = Path.Combine("output folder path", "SignWithDigitalIterative", fileName);
int iteration = 1;
string documentFile = filePath;

foreach (var certificatePath in certificatePaths)
{
    using (Signature signature = new Signature(documentFile))
    {
        DigitalSignOptions options = new DigitalSignOptions(certificatePath)
        {
            Password = "1234567890", // Certificate password
            Reason = $"Approved-{iteration}", // Digital certificate details
            Contact = $"John{iteration} Smith{iteration}",
            Location = $"Location-{iteration}",
            AllPages = true, // Sign all pages
            Left = 10 + 100 * (iteration - 1),
            Top = 10 + 100 * (iteration - 1),
            Width = 160,
            Height = 80,
            Margin = new Padding() { Bottom = 10, Right = 10 }
        };

        SignResult signResult = signature.Sign(outputFilePath, options);
        documentFile = outputFilePath;
        Console.WriteLine($"\nSource document signed successfully {iteration++}-time with {signResult.Succeeded.Count} signature(s).\nFile saved at {outputFilePath}.");
    }
}

More resources

GitHub Examples

You may easily run the code above and see the feature in action in ourย GitHub examples:

Free Online Apps

Along with the full-featured .NET library, we provide simple but powerful free online apps.

To sign PDF, Word, Excel, PowerPoint, and other documents you can use the online apps from the GroupDocs.Signature App Product Family.