Id
Contents
[
Hide
]SignatureLine.Id property
Gets or sets identifier for this signature line.
This identifier can be associated with a digital signature, when signing document using DigitalSignatureUtil
. This value must be unique and by default it is randomly generated new Guid (NewGuid).
public Guid Id { get; set; }
Examples
Shows how to add a signature line to a document, and then sign it using a digital certificate.
[Description("WORDSNET-16868")]
public static void Sign()
{
string signeeName = "Ron Williams";
string srcDocumentPath = MyDir + "Document.docx";
string dstDocumentPath = ArtifactsDir + "SignDocumentCustom.Sign.docx";
string certificatePath = MyDir + "morzal.pfx";
string certificatePassword = "aw";
CreateSignees();
Signee signeeInfo = mSignees.Find(c => c.Name == signeeName);
if (signeeInfo != null)
SignDocument(srcDocumentPath, dstDocumentPath, signeeInfo, certificatePath, certificatePassword);
else
Assert.Fail("Signee does not exist.");
}
/// <summary>
/// Creates a copy of a source document signed using provided signee information and X509 certificate.
/// </summary>
private static void SignDocument(string srcDocumentPath, string dstDocumentPath,
Signee signeeInfo, string certificatePath, string certificatePassword)
{
Document document = new Document(srcDocumentPath);
DocumentBuilder builder = new DocumentBuilder(document);
// Configure and insert a signature line, an object in the document that will display a signature that we sign it with.
SignatureLineOptions signatureLineOptions = new SignatureLineOptions
{
Signer = signeeInfo.Name,
SignerTitle = signeeInfo.Position
};
SignatureLine signatureLine = builder.InsertSignatureLine(signatureLineOptions).SignatureLine;
signatureLine.Id = signeeInfo.PersonId;
// First, we will save an unsigned version of our document.
builder.Document.Save(dstDocumentPath);
CertificateHolder certificateHolder = CertificateHolder.Create(certificatePath, certificatePassword);
SignOptions signOptions = new SignOptions
{
SignatureLineId = signeeInfo.PersonId,
SignatureLineImage = signeeInfo.Image
};
// Overwrite the unsigned document we saved above with a version signed using the certificate.
DigitalSignatureUtil.Sign(dstDocumentPath, dstDocumentPath, certificateHolder, signOptions);
}
public class Signee
{
public Guid PersonId { get; set; }
public string Name { get; set; }
public string Position { get; set; }
public byte[] Image { get; set; }
public Signee(Guid guid, string name, string position, byte[] image)
{
PersonId = guid;
Name = name;
Position = position;
Image = image;
}
}
private static void CreateSignees()
{
var signImagePath = ImageDir + "Logo.jpg";
mSignees = new List<Signee>
{
new Signee(Guid.NewGuid(), "Ron Williams", "Chief Executive Officer", TestUtil.ImageToByteArray(signImagePath)),
new Signee(Guid.NewGuid(), "Stephen Morse", "Head of Compliance", TestUtil.ImageToByteArray(signImagePath))
};
}
private static List<Signee> mSignees;
See Also
- class SignatureLine
- namespace Aspose.Words.Drawing
- assembly Aspose.Words