Skip to content

Instantly share code, notes, and snippets.

@GroupDocsGists
Last active March 14, 2021 06:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GroupDocsGists/ce12fd1c7f9f4c857413b1001586079d to your computer and use it in GitHub Desktop.
Save GroupDocsGists/ce12fd1c7f9f4c857413b1001586079d to your computer and use it in GitHub Desktop.
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