BoldDesk®Customer service software with ticketing, live chat & omnichannel support, starting at $99/mo for unlimited agents. Try for free!
//Load the existing PDF documnt.
PdfLoadedDocument document = new PdfLoadedDocument("../../Input.pdf");
//Get the page.
PdfLoadedPage page = document.Pages[0] as PdfLoadedPage;
//Create a new PDF signature instance.
PdfSignature signature = new PdfSignature(document, page, null, "Sig1");
//Set the signature bounds.
signature.Bounds = new RectangleF(0, 0, 200, 100);
//Call the compute hash event.
signature.ComputeHash += Signature_ComputeHash;
//Save the document.
document.Save("output.pdf");
//Close the document.
document.Close(true);
|
private void Signature_ComputeHash(object sender, PdfSignatureEventArgs ars)
{
//Get the document bytes.
byte[] documentBytes = ars.Data;
//Generate hash.
byte[] hash = SHA256.Create().ComputeHash(ars.Data);
//Include the signed data to PDF.
ars.SignedData = GetSignature(hash);
}
|