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.
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
stringfilePath="sample.pdf";stringfileName=Path.GetFileName(filePath);string[]certificatePaths=newstring[]{"certificate1.pfx","certificate2.pfx"};stringoutputFilePath=Path.Combine("output folder path","SignWithDigitalIterative",fileName);intiteration=1;stringdocumentFile=filePath;foreach(varcertificatePathincertificatePaths){using(Signaturesignature=newSignature(documentFile)){DigitalSignOptionsoptions=newDigitalSignOptions(certificatePath){Password="1234567890",// Certificate passwordReason=$"Approved-{iteration}",// Digital certificate detailsContact=$"John{iteration} Smith{iteration}",Location=$"Location-{iteration}",AllPages=true,// Sign all pagesLeft=10+100*(iteration-1),Top=10+100*(iteration-1),Width=160,Height=80,Margin=newPadding(){Bottom=10,Right=10}};SignResultsignResult=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: