SignatureLineOptions
Inheritance: java.lang.Object
public class SignatureLineOptions
Allows to specify options for signature line being inserted. Used in DocumentBuilder.
To learn more, visit the Work with Digital Signatures documentation article.
Examples:
Shows how to sign a document with a personal certificate and a signature line.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
SignatureLineOptions signatureLineOptions = new SignatureLineOptions();
signatureLineOptions.setSigner("vderyushev");
signatureLineOptions.setSignerTitle("QA");
signatureLineOptions.setEmail("vderyushev@aspose.com");
signatureLineOptions.setShowDate(true);
signatureLineOptions.setDefaultInstructions(false);
signatureLineOptions.setInstructions("Please sign here.");
signatureLineOptions.setAllowComments(true);
SignatureLine signatureLine = builder.insertSignatureLine(signatureLineOptions).getSignatureLine();
signatureLine.setProviderId(UUID.fromString("CF5A7BB4-8F3C-4756-9DF6-BEF7F13259A2"));
Assert.assertFalse(signatureLine.isSigned());
Assert.assertFalse(signatureLine.isValid());
doc.save(getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.docx");
Date currentDate = new Date();
SignOptions signOptions = new SignOptions();
signOptions.setSignatureLineId(signatureLine.getId());
signOptions.setProviderId(signatureLine.getProviderId());
signOptions.setComments("Document was signed by vderyushev");
signOptions.setSignTime(currentDate);
CertificateHolder certHolder = CertificateHolder.create(getMyDir() + "morzal.pfx", "aw");
DigitalSignatureUtil.sign(getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.docx",
getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.Signed.docx", certHolder, signOptions);
// Re-open our saved document, and verify that the "IsSigned" and "IsValid" properties both equal "true",
// indicating that the signature line contains a signature.
doc = new Document(getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.Signed.docx");
Shape shape = (Shape) doc.getChild(NodeType.SHAPE, 0, true);
signatureLine = shape.getSignatureLine();
Assert.assertTrue(signatureLine.isSigned());
Assert.assertTrue(signatureLine.isValid());
Methods
Method | Description |
---|---|
getAllowComments() | Gets a value indicating that the signer can add comments in the Sign dialog. |
getDefaultInstructions() | Gets a value indicating that default instructions is shown in the Sign dialog. |
getEmail() | Gets suggested signer’s e-mail address. |
getInstructions() | Gets instructions to the signer that are displayed on signing the signature line. |
getShowDate() | Gets a value indicating that sign date is shown in the signature line. |
getSigner() | Gets suggested signer of the signature line. |
getSignerTitle() | Gets suggested signer’s title. |
setAllowComments(boolean value) | Sets a value indicating that the signer can add comments in the Sign dialog. |
setDefaultInstructions(boolean value) | Sets a value indicating that default instructions is shown in the Sign dialog. |
setEmail(String value) | Sets suggested signer’s e-mail address. |
setInstructions(String value) | Sets instructions to the signer that are displayed on signing the signature line. |
setShowDate(boolean value) | Sets a value indicating that sign date is shown in the signature line. |
setSigner(String value) | Sets suggested signer of the signature line. |
setSignerTitle(String value) | Sets suggested signer’s title. |
getAllowComments()
public boolean getAllowComments()
Gets a value indicating that the signer can add comments in the Sign dialog. Default value for this property is false .
Examples:
Shows how to sign a document with a personal certificate and a signature line.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
SignatureLineOptions signatureLineOptions = new SignatureLineOptions();
signatureLineOptions.setSigner("vderyushev");
signatureLineOptions.setSignerTitle("QA");
signatureLineOptions.setEmail("vderyushev@aspose.com");
signatureLineOptions.setShowDate(true);
signatureLineOptions.setDefaultInstructions(false);
signatureLineOptions.setInstructions("Please sign here.");
signatureLineOptions.setAllowComments(true);
SignatureLine signatureLine = builder.insertSignatureLine(signatureLineOptions).getSignatureLine();
signatureLine.setProviderId(UUID.fromString("CF5A7BB4-8F3C-4756-9DF6-BEF7F13259A2"));
Assert.assertFalse(signatureLine.isSigned());
Assert.assertFalse(signatureLine.isValid());
doc.save(getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.docx");
Date currentDate = new Date();
SignOptions signOptions = new SignOptions();
signOptions.setSignatureLineId(signatureLine.getId());
signOptions.setProviderId(signatureLine.getProviderId());
signOptions.setComments("Document was signed by vderyushev");
signOptions.setSignTime(currentDate);
CertificateHolder certHolder = CertificateHolder.create(getMyDir() + "morzal.pfx", "aw");
DigitalSignatureUtil.sign(getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.docx",
getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.Signed.docx", certHolder, signOptions);
// Re-open our saved document, and verify that the "IsSigned" and "IsValid" properties both equal "true",
// indicating that the signature line contains a signature.
doc = new Document(getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.Signed.docx");
Shape shape = (Shape) doc.getChild(NodeType.SHAPE, 0, true);
signatureLine = shape.getSignatureLine();
Assert.assertTrue(signatureLine.isSigned());
Assert.assertTrue(signatureLine.isValid());
Returns: boolean - A value indicating that the signer can add comments in the Sign dialog.
getDefaultInstructions()
public boolean getDefaultInstructions()
Gets a value indicating that default instructions is shown in the Sign dialog. Default value for this property is true .
Examples:
Shows how to sign a document with a personal certificate and a signature line.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
SignatureLineOptions signatureLineOptions = new SignatureLineOptions();
signatureLineOptions.setSigner("vderyushev");
signatureLineOptions.setSignerTitle("QA");
signatureLineOptions.setEmail("vderyushev@aspose.com");
signatureLineOptions.setShowDate(true);
signatureLineOptions.setDefaultInstructions(false);
signatureLineOptions.setInstructions("Please sign here.");
signatureLineOptions.setAllowComments(true);
SignatureLine signatureLine = builder.insertSignatureLine(signatureLineOptions).getSignatureLine();
signatureLine.setProviderId(UUID.fromString("CF5A7BB4-8F3C-4756-9DF6-BEF7F13259A2"));
Assert.assertFalse(signatureLine.isSigned());
Assert.assertFalse(signatureLine.isValid());
doc.save(getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.docx");
Date currentDate = new Date();
SignOptions signOptions = new SignOptions();
signOptions.setSignatureLineId(signatureLine.getId());
signOptions.setProviderId(signatureLine.getProviderId());
signOptions.setComments("Document was signed by vderyushev");
signOptions.setSignTime(currentDate);
CertificateHolder certHolder = CertificateHolder.create(getMyDir() + "morzal.pfx", "aw");
DigitalSignatureUtil.sign(getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.docx",
getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.Signed.docx", certHolder, signOptions);
// Re-open our saved document, and verify that the "IsSigned" and "IsValid" properties both equal "true",
// indicating that the signature line contains a signature.
doc = new Document(getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.Signed.docx");
Shape shape = (Shape) doc.getChild(NodeType.SHAPE, 0, true);
signatureLine = shape.getSignatureLine();
Assert.assertTrue(signatureLine.isSigned());
Assert.assertTrue(signatureLine.isValid());
Returns: boolean - A value indicating that default instructions is shown in the Sign dialog.
getEmail()
public String getEmail()
Gets suggested signer’s e-mail address. Default value for this property is empty string.
Examples:
Shows how to sign a document with a personal certificate and a signature line.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
SignatureLineOptions signatureLineOptions = new SignatureLineOptions();
signatureLineOptions.setSigner("vderyushev");
signatureLineOptions.setSignerTitle("QA");
signatureLineOptions.setEmail("vderyushev@aspose.com");
signatureLineOptions.setShowDate(true);
signatureLineOptions.setDefaultInstructions(false);
signatureLineOptions.setInstructions("Please sign here.");
signatureLineOptions.setAllowComments(true);
SignatureLine signatureLine = builder.insertSignatureLine(signatureLineOptions).getSignatureLine();
signatureLine.setProviderId(UUID.fromString("CF5A7BB4-8F3C-4756-9DF6-BEF7F13259A2"));
Assert.assertFalse(signatureLine.isSigned());
Assert.assertFalse(signatureLine.isValid());
doc.save(getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.docx");
Date currentDate = new Date();
SignOptions signOptions = new SignOptions();
signOptions.setSignatureLineId(signatureLine.getId());
signOptions.setProviderId(signatureLine.getProviderId());
signOptions.setComments("Document was signed by vderyushev");
signOptions.setSignTime(currentDate);
CertificateHolder certHolder = CertificateHolder.create(getMyDir() + "morzal.pfx", "aw");
DigitalSignatureUtil.sign(getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.docx",
getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.Signed.docx", certHolder, signOptions);
// Re-open our saved document, and verify that the "IsSigned" and "IsValid" properties both equal "true",
// indicating that the signature line contains a signature.
doc = new Document(getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.Signed.docx");
Shape shape = (Shape) doc.getChild(NodeType.SHAPE, 0, true);
signatureLine = shape.getSignatureLine();
Assert.assertTrue(signatureLine.isSigned());
Assert.assertTrue(signatureLine.isValid());
Returns: java.lang.String - Suggested signer’s e-mail address.
getInstructions()
public String getInstructions()
Gets instructions to the signer that are displayed on signing the signature line. Default value for this property is empty string.
Examples:
Shows how to sign a document with a personal certificate and a signature line.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
SignatureLineOptions signatureLineOptions = new SignatureLineOptions();
signatureLineOptions.setSigner("vderyushev");
signatureLineOptions.setSignerTitle("QA");
signatureLineOptions.setEmail("vderyushev@aspose.com");
signatureLineOptions.setShowDate(true);
signatureLineOptions.setDefaultInstructions(false);
signatureLineOptions.setInstructions("Please sign here.");
signatureLineOptions.setAllowComments(true);
SignatureLine signatureLine = builder.insertSignatureLine(signatureLineOptions).getSignatureLine();
signatureLine.setProviderId(UUID.fromString("CF5A7BB4-8F3C-4756-9DF6-BEF7F13259A2"));
Assert.assertFalse(signatureLine.isSigned());
Assert.assertFalse(signatureLine.isValid());
doc.save(getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.docx");
Date currentDate = new Date();
SignOptions signOptions = new SignOptions();
signOptions.setSignatureLineId(signatureLine.getId());
signOptions.setProviderId(signatureLine.getProviderId());
signOptions.setComments("Document was signed by vderyushev");
signOptions.setSignTime(currentDate);
CertificateHolder certHolder = CertificateHolder.create(getMyDir() + "morzal.pfx", "aw");
DigitalSignatureUtil.sign(getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.docx",
getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.Signed.docx", certHolder, signOptions);
// Re-open our saved document, and verify that the "IsSigned" and "IsValid" properties both equal "true",
// indicating that the signature line contains a signature.
doc = new Document(getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.Signed.docx");
Shape shape = (Shape) doc.getChild(NodeType.SHAPE, 0, true);
signatureLine = shape.getSignatureLine();
Assert.assertTrue(signatureLine.isSigned());
Assert.assertTrue(signatureLine.isValid());
Returns: java.lang.String - Instructions to the signer that are displayed on signing the signature line.
getShowDate()
public boolean getShowDate()
Gets a value indicating that sign date is shown in the signature line. Default value for this property is true .
Examples:
Shows how to sign a document with a personal certificate and a signature line.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
SignatureLineOptions signatureLineOptions = new SignatureLineOptions();
signatureLineOptions.setSigner("vderyushev");
signatureLineOptions.setSignerTitle("QA");
signatureLineOptions.setEmail("vderyushev@aspose.com");
signatureLineOptions.setShowDate(true);
signatureLineOptions.setDefaultInstructions(false);
signatureLineOptions.setInstructions("Please sign here.");
signatureLineOptions.setAllowComments(true);
SignatureLine signatureLine = builder.insertSignatureLine(signatureLineOptions).getSignatureLine();
signatureLine.setProviderId(UUID.fromString("CF5A7BB4-8F3C-4756-9DF6-BEF7F13259A2"));
Assert.assertFalse(signatureLine.isSigned());
Assert.assertFalse(signatureLine.isValid());
doc.save(getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.docx");
Date currentDate = new Date();
SignOptions signOptions = new SignOptions();
signOptions.setSignatureLineId(signatureLine.getId());
signOptions.setProviderId(signatureLine.getProviderId());
signOptions.setComments("Document was signed by vderyushev");
signOptions.setSignTime(currentDate);
CertificateHolder certHolder = CertificateHolder.create(getMyDir() + "morzal.pfx", "aw");
DigitalSignatureUtil.sign(getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.docx",
getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.Signed.docx", certHolder, signOptions);
// Re-open our saved document, and verify that the "IsSigned" and "IsValid" properties both equal "true",
// indicating that the signature line contains a signature.
doc = new Document(getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.Signed.docx");
Shape shape = (Shape) doc.getChild(NodeType.SHAPE, 0, true);
signatureLine = shape.getSignatureLine();
Assert.assertTrue(signatureLine.isSigned());
Assert.assertTrue(signatureLine.isValid());
Returns: boolean - A value indicating that sign date is shown in the signature line.
getSigner()
public String getSigner()
Gets suggested signer of the signature line. Default value for this property is empty string.
Examples:
Shows how to add a signature line to a document, and then sign it using a digital certificate.
public static void sign() throws Exception {
String signPersonName = "Ron Williams";
String srcDocumentPath = getMyDir() + "Document.docx";
String dstDocumentPath = getArtifactsDir() + "SignDocumentCustom.Sign.docx";
String certificatePath = getMyDir() + "morzal.pfx";
String certificatePassword = "aw";
// We need to create simple list with test signers for this example.
createSignPersonData();
System.out.println("Test data successfully added!");
// Get sign person object by name of the person who must sign a document.
// This an example, in real use case you would return an object from a database.
SignPersonTestClass signPersonInfo = gSignPersonList.stream().filter(x -> x.getName() == signPersonName).findFirst().get();
if (signPersonInfo != null) {
signDocument(srcDocumentPath, dstDocumentPath, signPersonInfo, certificatePath, certificatePassword);
System.out.println("Document successfully signed!");
} else {
System.out.println("Sign person does not exist, please check your parameters.");
}
// Now do something with a signed document, for example, save it to your database.
// Use 'new Document(dstDocumentPath)' for loading a signed document.
}
///
/// Signs the document obtained at the source location and saves it to the specified destination.
///
private static void signDocument(final String srcDocumentPath, final String dstDocumentPath,
final SignPersonTestClass signPersonInfo, final String certificatePath,
final String certificatePassword) throws Exception {
// Create new document instance based on a test file that we need to sign.
Document document = new Document(srcDocumentPath);
DocumentBuilder builder = new DocumentBuilder(document);
// Add info about responsible person who sign a document.
SignatureLineOptions signatureLineOptions = new SignatureLineOptions();
signatureLineOptions.setSigner(signPersonInfo.getName());
signatureLineOptions.setSignerTitle(signPersonInfo.getPosition());
// Add signature line for responsible person who sign a document.
SignatureLine signatureLine = builder.insertSignatureLine(signatureLineOptions).getSignatureLine();
signatureLine.setId(signPersonInfo.getPersonId());
// Save a document with line signatures into temporary file for future signing.
builder.getDocument().save(dstDocumentPath);
// Create holder of certificate instance based on your personal certificate.
// This is the test certificate generated for this example.
CertificateHolder certificateHolder = CertificateHolder.create(certificatePath, certificatePassword);
// Link our signature line with personal signature.
SignOptions signOptions = new SignOptions();
signOptions.setSignatureLineId(signPersonInfo.getPersonId());
signOptions.setSignatureLineImage(signPersonInfo.getImage());
// Sign a document which contains signature line with personal certificate.
DigitalSignatureUtil.sign(dstDocumentPath, dstDocumentPath, certificateHolder, signOptions);
}
///
/// Create test data that contains info about sing persons.
///
private static void createSignPersonData() throws IOException {
InputStream inputStream = new FileInputStream(getImageDir() + "Logo.jpg");
gSignPersonList = new ArrayList<>();
gSignPersonList.add(new SignPersonTestClass(UUID.randomUUID(), "Ron Williams", "Chief Executive Officer",
DocumentHelper.getBytesFromStream(inputStream)));
gSignPersonList.add(new SignPersonTestClass(UUID.randomUUID(), "Stephen Morse", "Head of Compliance",
DocumentHelper.getBytesFromStream(inputStream)));
}
private static ArrayList gSignPersonList;
Returns: java.lang.String - Suggested signer of the signature line.
getSignerTitle()
public String getSignerTitle()
Gets suggested signer’s title. Default value for this property is empty string.
Examples:
Shows how to add a signature line to a document, and then sign it using a digital certificate.
public static void sign() throws Exception {
String signPersonName = "Ron Williams";
String srcDocumentPath = getMyDir() + "Document.docx";
String dstDocumentPath = getArtifactsDir() + "SignDocumentCustom.Sign.docx";
String certificatePath = getMyDir() + "morzal.pfx";
String certificatePassword = "aw";
// We need to create simple list with test signers for this example.
createSignPersonData();
System.out.println("Test data successfully added!");
// Get sign person object by name of the person who must sign a document.
// This an example, in real use case you would return an object from a database.
SignPersonTestClass signPersonInfo = gSignPersonList.stream().filter(x -> x.getName() == signPersonName).findFirst().get();
if (signPersonInfo != null) {
signDocument(srcDocumentPath, dstDocumentPath, signPersonInfo, certificatePath, certificatePassword);
System.out.println("Document successfully signed!");
} else {
System.out.println("Sign person does not exist, please check your parameters.");
}
// Now do something with a signed document, for example, save it to your database.
// Use 'new Document(dstDocumentPath)' for loading a signed document.
}
///
/// Signs the document obtained at the source location and saves it to the specified destination.
///
private static void signDocument(final String srcDocumentPath, final String dstDocumentPath,
final SignPersonTestClass signPersonInfo, final String certificatePath,
final String certificatePassword) throws Exception {
// Create new document instance based on a test file that we need to sign.
Document document = new Document(srcDocumentPath);
DocumentBuilder builder = new DocumentBuilder(document);
// Add info about responsible person who sign a document.
SignatureLineOptions signatureLineOptions = new SignatureLineOptions();
signatureLineOptions.setSigner(signPersonInfo.getName());
signatureLineOptions.setSignerTitle(signPersonInfo.getPosition());
// Add signature line for responsible person who sign a document.
SignatureLine signatureLine = builder.insertSignatureLine(signatureLineOptions).getSignatureLine();
signatureLine.setId(signPersonInfo.getPersonId());
// Save a document with line signatures into temporary file for future signing.
builder.getDocument().save(dstDocumentPath);
// Create holder of certificate instance based on your personal certificate.
// This is the test certificate generated for this example.
CertificateHolder certificateHolder = CertificateHolder.create(certificatePath, certificatePassword);
// Link our signature line with personal signature.
SignOptions signOptions = new SignOptions();
signOptions.setSignatureLineId(signPersonInfo.getPersonId());
signOptions.setSignatureLineImage(signPersonInfo.getImage());
// Sign a document which contains signature line with personal certificate.
DigitalSignatureUtil.sign(dstDocumentPath, dstDocumentPath, certificateHolder, signOptions);
}
///
/// Create test data that contains info about sing persons.
///
private static void createSignPersonData() throws IOException {
InputStream inputStream = new FileInputStream(getImageDir() + "Logo.jpg");
gSignPersonList = new ArrayList<>();
gSignPersonList.add(new SignPersonTestClass(UUID.randomUUID(), "Ron Williams", "Chief Executive Officer",
DocumentHelper.getBytesFromStream(inputStream)));
gSignPersonList.add(new SignPersonTestClass(UUID.randomUUID(), "Stephen Morse", "Head of Compliance",
DocumentHelper.getBytesFromStream(inputStream)));
}
private static ArrayList gSignPersonList;
Returns: java.lang.String - Suggested signer’s title.
setAllowComments(boolean value)
public void setAllowComments(boolean value)
Sets a value indicating that the signer can add comments in the Sign dialog. Default value for this property is false .
Examples:
Shows how to sign a document with a personal certificate and a signature line.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
SignatureLineOptions signatureLineOptions = new SignatureLineOptions();
signatureLineOptions.setSigner("vderyushev");
signatureLineOptions.setSignerTitle("QA");
signatureLineOptions.setEmail("vderyushev@aspose.com");
signatureLineOptions.setShowDate(true);
signatureLineOptions.setDefaultInstructions(false);
signatureLineOptions.setInstructions("Please sign here.");
signatureLineOptions.setAllowComments(true);
SignatureLine signatureLine = builder.insertSignatureLine(signatureLineOptions).getSignatureLine();
signatureLine.setProviderId(UUID.fromString("CF5A7BB4-8F3C-4756-9DF6-BEF7F13259A2"));
Assert.assertFalse(signatureLine.isSigned());
Assert.assertFalse(signatureLine.isValid());
doc.save(getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.docx");
Date currentDate = new Date();
SignOptions signOptions = new SignOptions();
signOptions.setSignatureLineId(signatureLine.getId());
signOptions.setProviderId(signatureLine.getProviderId());
signOptions.setComments("Document was signed by vderyushev");
signOptions.setSignTime(currentDate);
CertificateHolder certHolder = CertificateHolder.create(getMyDir() + "morzal.pfx", "aw");
DigitalSignatureUtil.sign(getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.docx",
getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.Signed.docx", certHolder, signOptions);
// Re-open our saved document, and verify that the "IsSigned" and "IsValid" properties both equal "true",
// indicating that the signature line contains a signature.
doc = new Document(getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.Signed.docx");
Shape shape = (Shape) doc.getChild(NodeType.SHAPE, 0, true);
signatureLine = shape.getSignatureLine();
Assert.assertTrue(signatureLine.isSigned());
Assert.assertTrue(signatureLine.isValid());
Parameters:
Parameter | Type | Description |
---|---|---|
value | boolean | A value indicating that the signer can add comments in the Sign dialog. |
setDefaultInstructions(boolean value)
public void setDefaultInstructions(boolean value)
Sets a value indicating that default instructions is shown in the Sign dialog. Default value for this property is true .
Examples:
Shows how to sign a document with a personal certificate and a signature line.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
SignatureLineOptions signatureLineOptions = new SignatureLineOptions();
signatureLineOptions.setSigner("vderyushev");
signatureLineOptions.setSignerTitle("QA");
signatureLineOptions.setEmail("vderyushev@aspose.com");
signatureLineOptions.setShowDate(true);
signatureLineOptions.setDefaultInstructions(false);
signatureLineOptions.setInstructions("Please sign here.");
signatureLineOptions.setAllowComments(true);
SignatureLine signatureLine = builder.insertSignatureLine(signatureLineOptions).getSignatureLine();
signatureLine.setProviderId(UUID.fromString("CF5A7BB4-8F3C-4756-9DF6-BEF7F13259A2"));
Assert.assertFalse(signatureLine.isSigned());
Assert.assertFalse(signatureLine.isValid());
doc.save(getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.docx");
Date currentDate = new Date();
SignOptions signOptions = new SignOptions();
signOptions.setSignatureLineId(signatureLine.getId());
signOptions.setProviderId(signatureLine.getProviderId());
signOptions.setComments("Document was signed by vderyushev");
signOptions.setSignTime(currentDate);
CertificateHolder certHolder = CertificateHolder.create(getMyDir() + "morzal.pfx", "aw");
DigitalSignatureUtil.sign(getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.docx",
getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.Signed.docx", certHolder, signOptions);
// Re-open our saved document, and verify that the "IsSigned" and "IsValid" properties both equal "true",
// indicating that the signature line contains a signature.
doc = new Document(getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.Signed.docx");
Shape shape = (Shape) doc.getChild(NodeType.SHAPE, 0, true);
signatureLine = shape.getSignatureLine();
Assert.assertTrue(signatureLine.isSigned());
Assert.assertTrue(signatureLine.isValid());
Parameters:
Parameter | Type | Description |
---|---|---|
value | boolean | A value indicating that default instructions is shown in the Sign dialog. |
setEmail(String value)
public void setEmail(String value)
Sets suggested signer’s e-mail address. Default value for this property is empty string.
Examples:
Shows how to sign a document with a personal certificate and a signature line.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
SignatureLineOptions signatureLineOptions = new SignatureLineOptions();
signatureLineOptions.setSigner("vderyushev");
signatureLineOptions.setSignerTitle("QA");
signatureLineOptions.setEmail("vderyushev@aspose.com");
signatureLineOptions.setShowDate(true);
signatureLineOptions.setDefaultInstructions(false);
signatureLineOptions.setInstructions("Please sign here.");
signatureLineOptions.setAllowComments(true);
SignatureLine signatureLine = builder.insertSignatureLine(signatureLineOptions).getSignatureLine();
signatureLine.setProviderId(UUID.fromString("CF5A7BB4-8F3C-4756-9DF6-BEF7F13259A2"));
Assert.assertFalse(signatureLine.isSigned());
Assert.assertFalse(signatureLine.isValid());
doc.save(getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.docx");
Date currentDate = new Date();
SignOptions signOptions = new SignOptions();
signOptions.setSignatureLineId(signatureLine.getId());
signOptions.setProviderId(signatureLine.getProviderId());
signOptions.setComments("Document was signed by vderyushev");
signOptions.setSignTime(currentDate);
CertificateHolder certHolder = CertificateHolder.create(getMyDir() + "morzal.pfx", "aw");
DigitalSignatureUtil.sign(getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.docx",
getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.Signed.docx", certHolder, signOptions);
// Re-open our saved document, and verify that the "IsSigned" and "IsValid" properties both equal "true",
// indicating that the signature line contains a signature.
doc = new Document(getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.Signed.docx");
Shape shape = (Shape) doc.getChild(NodeType.SHAPE, 0, true);
signatureLine = shape.getSignatureLine();
Assert.assertTrue(signatureLine.isSigned());
Assert.assertTrue(signatureLine.isValid());
Parameters:
Parameter | Type | Description |
---|---|---|
value | java.lang.String | Suggested signer’s e-mail address. |
setInstructions(String value)
public void setInstructions(String value)
Sets instructions to the signer that are displayed on signing the signature line. Default value for this property is empty string.
Examples:
Shows how to sign a document with a personal certificate and a signature line.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
SignatureLineOptions signatureLineOptions = new SignatureLineOptions();
signatureLineOptions.setSigner("vderyushev");
signatureLineOptions.setSignerTitle("QA");
signatureLineOptions.setEmail("vderyushev@aspose.com");
signatureLineOptions.setShowDate(true);
signatureLineOptions.setDefaultInstructions(false);
signatureLineOptions.setInstructions("Please sign here.");
signatureLineOptions.setAllowComments(true);
SignatureLine signatureLine = builder.insertSignatureLine(signatureLineOptions).getSignatureLine();
signatureLine.setProviderId(UUID.fromString("CF5A7BB4-8F3C-4756-9DF6-BEF7F13259A2"));
Assert.assertFalse(signatureLine.isSigned());
Assert.assertFalse(signatureLine.isValid());
doc.save(getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.docx");
Date currentDate = new Date();
SignOptions signOptions = new SignOptions();
signOptions.setSignatureLineId(signatureLine.getId());
signOptions.setProviderId(signatureLine.getProviderId());
signOptions.setComments("Document was signed by vderyushev");
signOptions.setSignTime(currentDate);
CertificateHolder certHolder = CertificateHolder.create(getMyDir() + "morzal.pfx", "aw");
DigitalSignatureUtil.sign(getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.docx",
getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.Signed.docx", certHolder, signOptions);
// Re-open our saved document, and verify that the "IsSigned" and "IsValid" properties both equal "true",
// indicating that the signature line contains a signature.
doc = new Document(getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.Signed.docx");
Shape shape = (Shape) doc.getChild(NodeType.SHAPE, 0, true);
signatureLine = shape.getSignatureLine();
Assert.assertTrue(signatureLine.isSigned());
Assert.assertTrue(signatureLine.isValid());
Parameters:
Parameter | Type | Description |
---|---|---|
value | java.lang.String | Instructions to the signer that are displayed on signing the signature line. |
setShowDate(boolean value)
public void setShowDate(boolean value)
Sets a value indicating that sign date is shown in the signature line. Default value for this property is true .
Examples:
Shows how to sign a document with a personal certificate and a signature line.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
SignatureLineOptions signatureLineOptions = new SignatureLineOptions();
signatureLineOptions.setSigner("vderyushev");
signatureLineOptions.setSignerTitle("QA");
signatureLineOptions.setEmail("vderyushev@aspose.com");
signatureLineOptions.setShowDate(true);
signatureLineOptions.setDefaultInstructions(false);
signatureLineOptions.setInstructions("Please sign here.");
signatureLineOptions.setAllowComments(true);
SignatureLine signatureLine = builder.insertSignatureLine(signatureLineOptions).getSignatureLine();
signatureLine.setProviderId(UUID.fromString("CF5A7BB4-8F3C-4756-9DF6-BEF7F13259A2"));
Assert.assertFalse(signatureLine.isSigned());
Assert.assertFalse(signatureLine.isValid());
doc.save(getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.docx");
Date currentDate = new Date();
SignOptions signOptions = new SignOptions();
signOptions.setSignatureLineId(signatureLine.getId());
signOptions.setProviderId(signatureLine.getProviderId());
signOptions.setComments("Document was signed by vderyushev");
signOptions.setSignTime(currentDate);
CertificateHolder certHolder = CertificateHolder.create(getMyDir() + "morzal.pfx", "aw");
DigitalSignatureUtil.sign(getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.docx",
getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.Signed.docx", certHolder, signOptions);
// Re-open our saved document, and verify that the "IsSigned" and "IsValid" properties both equal "true",
// indicating that the signature line contains a signature.
doc = new Document(getArtifactsDir() + "DocumentBuilder.SignatureLineProviderId.Signed.docx");
Shape shape = (Shape) doc.getChild(NodeType.SHAPE, 0, true);
signatureLine = shape.getSignatureLine();
Assert.assertTrue(signatureLine.isSigned());
Assert.assertTrue(signatureLine.isValid());
Parameters:
Parameter | Type | Description |
---|---|---|
value | boolean | A value indicating that sign date is shown in the signature line. |
setSigner(String value)
public void setSigner(String value)
Sets suggested signer of the signature line. Default value for this property is empty string.
Examples:
Shows how to add a signature line to a document, and then sign it using a digital certificate.
public static void sign() throws Exception {
String signPersonName = "Ron Williams";
String srcDocumentPath = getMyDir() + "Document.docx";
String dstDocumentPath = getArtifactsDir() + "SignDocumentCustom.Sign.docx";
String certificatePath = getMyDir() + "morzal.pfx";
String certificatePassword = "aw";
// We need to create simple list with test signers for this example.
createSignPersonData();
System.out.println("Test data successfully added!");
// Get sign person object by name of the person who must sign a document.
// This an example, in real use case you would return an object from a database.
SignPersonTestClass signPersonInfo = gSignPersonList.stream().filter(x -> x.getName() == signPersonName).findFirst().get();
if (signPersonInfo != null) {
signDocument(srcDocumentPath, dstDocumentPath, signPersonInfo, certificatePath, certificatePassword);
System.out.println("Document successfully signed!");
} else {
System.out.println("Sign person does not exist, please check your parameters.");
}
// Now do something with a signed document, for example, save it to your database.
// Use 'new Document(dstDocumentPath)' for loading a signed document.
}
///
/// Signs the document obtained at the source location and saves it to the specified destination.
///
private static void signDocument(final String srcDocumentPath, final String dstDocumentPath,
final SignPersonTestClass signPersonInfo, final String certificatePath,
final String certificatePassword) throws Exception {
// Create new document instance based on a test file that we need to sign.
Document document = new Document(srcDocumentPath);
DocumentBuilder builder = new DocumentBuilder(document);
// Add info about responsible person who sign a document.
SignatureLineOptions signatureLineOptions = new SignatureLineOptions();
signatureLineOptions.setSigner(signPersonInfo.getName());
signatureLineOptions.setSignerTitle(signPersonInfo.getPosition());
// Add signature line for responsible person who sign a document.
SignatureLine signatureLine = builder.insertSignatureLine(signatureLineOptions).getSignatureLine();
signatureLine.setId(signPersonInfo.getPersonId());
// Save a document with line signatures into temporary file for future signing.
builder.getDocument().save(dstDocumentPath);
// Create holder of certificate instance based on your personal certificate.
// This is the test certificate generated for this example.
CertificateHolder certificateHolder = CertificateHolder.create(certificatePath, certificatePassword);
// Link our signature line with personal signature.
SignOptions signOptions = new SignOptions();
signOptions.setSignatureLineId(signPersonInfo.getPersonId());
signOptions.setSignatureLineImage(signPersonInfo.getImage());
// Sign a document which contains signature line with personal certificate.
DigitalSignatureUtil.sign(dstDocumentPath, dstDocumentPath, certificateHolder, signOptions);
}
///
/// Create test data that contains info about sing persons.
///
private static void createSignPersonData() throws IOException {
InputStream inputStream = new FileInputStream(getImageDir() + "Logo.jpg");
gSignPersonList = new ArrayList<>();
gSignPersonList.add(new SignPersonTestClass(UUID.randomUUID(), "Ron Williams", "Chief Executive Officer",
DocumentHelper.getBytesFromStream(inputStream)));
gSignPersonList.add(new SignPersonTestClass(UUID.randomUUID(), "Stephen Morse", "Head of Compliance",
DocumentHelper.getBytesFromStream(inputStream)));
}
private static ArrayList gSignPersonList;
Parameters:
Parameter | Type | Description |
---|---|---|
value | java.lang.String | Suggested signer of the signature line. |
setSignerTitle(String value)
public void setSignerTitle(String value)
Sets suggested signer’s title. Default value for this property is empty string.
Examples:
Shows how to add a signature line to a document, and then sign it using a digital certificate.
public static void sign() throws Exception {
String signPersonName = "Ron Williams";
String srcDocumentPath = getMyDir() + "Document.docx";
String dstDocumentPath = getArtifactsDir() + "SignDocumentCustom.Sign.docx";
String certificatePath = getMyDir() + "morzal.pfx";
String certificatePassword = "aw";
// We need to create simple list with test signers for this example.
createSignPersonData();
System.out.println("Test data successfully added!");
// Get sign person object by name of the person who must sign a document.
// This an example, in real use case you would return an object from a database.
SignPersonTestClass signPersonInfo = gSignPersonList.stream().filter(x -> x.getName() == signPersonName).findFirst().get();
if (signPersonInfo != null) {
signDocument(srcDocumentPath, dstDocumentPath, signPersonInfo, certificatePath, certificatePassword);
System.out.println("Document successfully signed!");
} else {
System.out.println("Sign person does not exist, please check your parameters.");
}
// Now do something with a signed document, for example, save it to your database.
// Use 'new Document(dstDocumentPath)' for loading a signed document.
}
///
/// Signs the document obtained at the source location and saves it to the specified destination.
///
private static void signDocument(final String srcDocumentPath, final String dstDocumentPath,
final SignPersonTestClass signPersonInfo, final String certificatePath,
final String certificatePassword) throws Exception {
// Create new document instance based on a test file that we need to sign.
Document document = new Document(srcDocumentPath);
DocumentBuilder builder = new DocumentBuilder(document);
// Add info about responsible person who sign a document.
SignatureLineOptions signatureLineOptions = new SignatureLineOptions();
signatureLineOptions.setSigner(signPersonInfo.getName());
signatureLineOptions.setSignerTitle(signPersonInfo.getPosition());
// Add signature line for responsible person who sign a document.
SignatureLine signatureLine = builder.insertSignatureLine(signatureLineOptions).getSignatureLine();
signatureLine.setId(signPersonInfo.getPersonId());
// Save a document with line signatures into temporary file for future signing.
builder.getDocument().save(dstDocumentPath);
// Create holder of certificate instance based on your personal certificate.
// This is the test certificate generated for this example.
CertificateHolder certificateHolder = CertificateHolder.create(certificatePath, certificatePassword);
// Link our signature line with personal signature.
SignOptions signOptions = new SignOptions();
signOptions.setSignatureLineId(signPersonInfo.getPersonId());
signOptions.setSignatureLineImage(signPersonInfo.getImage());
// Sign a document which contains signature line with personal certificate.
DigitalSignatureUtil.sign(dstDocumentPath, dstDocumentPath, certificateHolder, signOptions);
}
///
/// Create test data that contains info about sing persons.
///
private static void createSignPersonData() throws IOException {
InputStream inputStream = new FileInputStream(getImageDir() + "Logo.jpg");
gSignPersonList = new ArrayList<>();
gSignPersonList.add(new SignPersonTestClass(UUID.randomUUID(), "Ron Williams", "Chief Executive Officer",
DocumentHelper.getBytesFromStream(inputStream)));
gSignPersonList.add(new SignPersonTestClass(UUID.randomUUID(), "Stephen Morse", "Head of Compliance",
DocumentHelper.getBytesFromStream(inputStream)));
}
private static ArrayList gSignPersonList;
Parameters:
Parameter | Type | Description |
---|---|---|
value | java.lang.String | Suggested signer’s title. |