Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ static void Main(string[] args)
SignatureSettings settings = new SignatureSettings();
settings.Comments = "Approved";
settings.SignTime = DateTime.Now;
//Sets the application version used to create the signature.
settings.ApplicationVersion = "16.0";
//Sets the Office version recorded with the signature.
settings.OfficeVersion = "16.0";
//Sets the Windows version recorded with the signature.
settings.WindowsVersion = "10.0";
//Sets the horizontal resolution recorded with the signature.
settings.HorizontalResolution = 1920;
//Sets the vertical resolution recorded with the signature.
settings.VerticalResolution = 1080;
//Sets the color depth recorded with the signature.
settings.ColorDepth = 32;
//Sets the cryptographic provider identifier.
settings.ProviderId = new Guid("00000000-0000-0000-0000-000000000000");
//Adds an invisible digital signature to the document using the certificate and settings.
document.AddDigitalSignature(certificate, settings);
//Saves the Word document to file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ static void Main(string[] args)
settings.SignerTitle = "Manager";
settings.Email = "john.doe@example.com";
settings.Instructions = "Please review and sign.";
//Specifies whether the signer can attach comments when signing.
settings.AllowComments = true;
//Specifies whether the sign date is displayed on the signature line.
settings.ShowDate = true;
//Specifies whether the default signing instructions are used (false uses the custom Instructions value).
settings.DefaultInstructions = false;
//Inserts the signature line into the new paragraph with the specified dimensions.
IWPicture picture = signatureParagraph.AppendSignatureLine(settings, 200, 100);
//Saves the Word document to file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,116 @@ static void Main(string[] args)
// Gets the digital signature collection in the document.
OfficeDigitalSignatureCollection signatures = document.DigitalSignatures;

// Gets the number of digital signatures in the document.
int signatureCount = signatures.Count;
Console.WriteLine("Signature count: " + signatureCount);

// Checks whether every digital signature in the collection is valid.
bool allValid = signatures.IsValid;
Console.WriteLine("All signatures are valid: " + allValid);

// Displays details of each signature.
foreach (OfficeDigitalSignature signature in signatures)
{
Console.WriteLine("Signature comments: " + signature.Comments);
Console.WriteLine("Time of signing: " + signature.SigningTime);
Console.WriteLine("Subject name: " +
signature.Certificate.Subject);
Console.WriteLine("Issuer name: " +
signature.Certificate.Issuer);
// Checks whether the signature is valid.
bool isValid = signature.IsValid;
// Gets the comments recorded with the signature.
string comments = signature.Comments;
// Gets the timestamp recorded with the signature.
DateTime signingTime = signature.SigningTime;
// Gets the application version recorded with the signature.
string applicationVersion = signature.ApplicationVersion;
// Gets the Office version recorded with the signature.
string officeVersion = signature.OfficeVersion;
// Gets the Windows version recorded with the signature.
string windowsVersion = signature.WindowsVersion;
// Gets the color depth recorded with the signature.
int colorDepth = signature.ColorDepth;
// Gets the horizontal resolution recorded with the signature.
float horizontalResolution = signature.HorizontalResolution;
// Gets the vertical resolution recorded with the signature.
float verticalResolution = signature.VerticalResolution;
// Gets the raw signature value bytes.
byte[] signatureValue = signature.SignatureValue;
// Gets the certificate used to create the signature.
OfficeDigitalSignatureCertificate certificate = signature.Certificate;

Console.WriteLine("Signature is valid: " + isValid);
Console.WriteLine("Comments: " + comments);
Console.WriteLine("Signing time: " + signingTime);
Console.WriteLine("Application version: " + applicationVersion);
Console.WriteLine("Office version: " + officeVersion);
Console.WriteLine("Windows version: " + windowsVersion);
Console.WriteLine("Color depth: " + colorDepth);
Console.WriteLine("Horizontal resolution: " + horizontalResolution);
Console.WriteLine("Vertical resolution: " + verticalResolution);
Console.WriteLine("Signature value length: " + (signatureValue != null ? signatureValue.Length : 0));

if (certificate != null)
{
// Gets the certificate subject.
string subject = certificate.Subject;
// Gets the certificate issuer.
string issuer = certificate.Issuer;
// Gets the certificate serial number.
string serialNumber = certificate.SerialNumber;
// Gets the certificate thumbprint.
string thumbprint = certificate.Thumbprint;
// Gets the date the certificate is valid from.
DateTime validFrom = certificate.ValidFrom;
// Gets the date the certificate is valid to.
DateTime validTo = certificate.ValidTo;

Console.WriteLine("Subject name: " + subject);
Console.WriteLine("Issuer name: " + issuer);
Console.WriteLine("Serial number: " + serialNumber);
Console.WriteLine("Thumbprint: " + thumbprint);
Console.WriteLine("Valid from: " + validFrom);
Console.WriteLine("Valid to: " + validTo);
}

Console.WriteLine();
}

// Retrieves a specific signature by index from the collection.
if (signatures.Count > 0)
{
OfficeDigitalSignature firstSignature = signatures[0];
Console.WriteLine("First signature comments: " + firstSignature.Comments);
}

// Walks the document body and reads the properties of any signature line shapes.
foreach (WSection section in document.Sections)
{
foreach (WParagraph paragraph in section.Paragraphs)
{
foreach (Entity entity in paragraph.ChildEntities)
{
if (entity is WPicture picture && picture.IsSignatureLine)
{
OfficeSignatureLine signatureLine = picture.SignatureLine;

// Gets the unique identifier of the signature line.
Guid id = signatureLine.Id;
// Gets the instructions displayed to the signer.
string instructions = signatureLine.Instructions;
// Gets whether the signer can attach comments when signing.
bool allowComments = signatureLine.AllowComments;
// Gets whether the sign date is displayed on the signature line.
bool showDate = signatureLine.ShowDate;
// Gets whether the signature line has been signed.
bool isSigned = signatureLine.IsSigned;

Console.WriteLine("Signature line id: " + id);
Console.WriteLine("Signature line instructions: " + instructions);
Console.WriteLine("Signature line allow comments: " + allowComments);
Console.WriteLine("Signature line show date: " + showDate);
Console.WriteLine("Signature line is signed: " + isSigned);
}
}
}
}

// Closes the document.
document.Close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ class Program
static void Main(string[] args)
{
//Opens an existing Word document with signature line.
using (WordDocument document =
new WordDocument(
Path.GetFullPath(@"Data\Template.docx")))
using (WordDocument document = new WordDocument(Path.GetFullPath(@"Data\Template.docx")))
{
WPicture picture = null;
OfficeSignatureLine signatureLine = null;
Expand All @@ -30,11 +28,9 @@ static void Main(string[] args)
break;
}
}

if (picture != null)
break;
}

if (picture != null)
break;
}
Expand Down
Loading