Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sign Document with Digital Signatures in C#
// Sign PDF with digital certificate in C#
using (Signature signature = new Signature("document.pdf"))
{
DigitalSignOptions options = new DigitalSignOptions("certificate.pfx");
{
ImageFilePath = "sampleImage.jpg", // Optional - Set image file path
Left = 50, // Set signature position
Top = 50,
Password = "GroupDocs" // Set Password
};
signature.Sign("signedDocument.pdf", options);
}
// Sign PDF with digital certificate in C# with custom appearance and setting
using (Signature signature = new Signature("document.pdf"))
{
DigitalSignOptions options = new DigitalSignOptions("certificate.pfx")
{
Password = "GroupDocs",
// digital certificate details
Reason = "Approved",
Location = "New York",
// Custom PDF signature appearance
Appearance = new PdfDigitalSignatureAppearance()
{
// Do not show contact details
ContactInfoLabel = string.Empty,
// Simplify Reason Label
ReasonLabel = "?",
// Change Location Label
LocationLabel = "From",
DigitalSignedLabel = "By",
DateSignedAtLabel = "On",
Background = Color.Red
},
AllPages = true,
Width = 160,
Height = 80,
// Set signature border
Border = new Border()
{
Visible = true,
Color = Color.Red,
DashStyle = DashStyle.DashDot,
Weight = 2
}
};
SignResult signResult = signature.Sign("signedDocument.pdf", options);
}
// Sign Word document with digital certificate in C#
using (Signature signature = new Signature("document.docx"))
{
DigitalSignOptions options = new DigitalSignOptions("certificate.pfx");
{
ImageFilePath = "sampleImage.jpg", // Optional - Set image file path
Left = 50, // Set signature position
Top = 50,
Password = "GroupDocs" // Set Password
};
signature.Sign("signedDocument.docx", options);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment