Locating signature on page with different measure units
GroupDocs.Signature supports locating signature on document page with different measure units. Enumeration MeasureType handles following types
- MeasureType.Pixels allows to locate signature position and size with pixels (default value)
- MeasureType.Millimeters allows to locate signature on page and setup size by setting millimeters
- MeasureType.Percents allows to locate signature position, size with percentage of page size
Here are the steps to locate and size signature area with different measure unit types:
- Set property setLocationMeasureType with of one values above to specify how to implement values in properties setLeft, setTop
- Set property setSizeMeasureType with of one values above to specify how to implement size of signature values in properties setWidth, setHeight
- Set property setMarginMeasureType with of one values above to specify how to implement values in property setMargin
Set signature positioning in millimeters
This example shows how to specify positioning in millimeters.
// instantiating the signature object
final Signature signature = new Signature("sample.docx");
try
{
// setup options with text of signature
BarcodeSignOptions signOptions = new BarcodeSignOptions("12345678");
// setup Barcode encoding type
signOptions.setEncodeType(BarcodeTypes.Code128);
// set signature position in absolute position
signOptions.setLocationMeasureType(MeasureType.Millimeters);
signOptions.setLeft(40);
signOptions.setTop(50);
// set signature area in millimeters
signOptions.setSizeMeasureType(MeasureType.Millimeters);
signOptions.setWidth(20);
signOptions.setHeight(10);
// set margin in millimeters
signOptions.setMarginMeasureType(MeasureType.Millimeters);
Padding padding = new Padding();
padding.setTop(5);
padding.setLeft(5);
padding.setRight(5);
signOptions.setMargin(padding);
// sign document
SignResult signResult = signature.sign("signedSample.docx", options);
// analyzing result
System.out.print("List of newly created signatures:");
int number = 1;
for(BaseSignature temp : signResult.getSucceeded())
{
System.out.print("Signature #"+ number++ +": Type: "+temp.getSignatureType()+" Id:"+temp.getSignatureId()+
",Location: "+temp.getLeft()+"x"+temp.getTop()+". Size: "+temp.getWidth()+"x"+temp.getHeight());
}
}catch (Exception e){
throw new GroupDocsSignatureException(e.getMessage());
}
Set signature positioning in percents
This example shows how to set different positioning properties in percentage.
// instantiating the signature object
final Signature signature = new Signature("sample.pdf");
try
{
// setup options with text of signature
BarcodeSignOptions signOptions = new BarcodeSignOptions("12345678");
// setup Barcode encoding type
signOptions.setEncodeType(BarcodeTypes.Code128);
// set signature position in absolute position
signOptions.setLocationMeasureType(MeasureType.Percents);
signOptions.setLeft(5);
signOptions.setTop(5);
// set signature area in percents
signOptions.setSizeMeasureType(MeasureType.Percents);
signOptions.setWidth(10);
signOptions.setHeight(5);
// set margin in millimeters
signOptions.setMarginMeasureType(MeasureType.Percents);
Padding padding = new Padding();
padding.setTop(1);
padding.setLeft(1);
padding.setRight(1);
signOptions.setMargin(padding);
// sign document
SignResult signResult = signature.sign("signed.docx", options);
// analyzing result
System.out.print("List of newly created signatures:");
int number = 1;
for(BaseSignature temp : signResult.getSucceeded())
{
System.out.print("Signature #"+ number++ +": Type: "+temp.getSignatureType()+" Id:"+temp.getSignatureId()+
",Location: "+temp.getLeft()+"x"+temp.getTop()+". Size: "+temp.getWidth()+"x"+temp.getHeight());
}
}catch (Exception e){
throw new GroupDocsSignatureException(e.getMessage());
}
More resources
GitHub Examples
You may easily run the code above and see the feature in action in our GitHub examples:
- GroupDocs.Signature for .NET examples, plugins, and showcase
- GroupDocs.Signature for Java examples, plugins, and showcase
- Document Signature for .NET MVC UI Example
- Document Signature for .NET App WebForms UI Example
- Document Signature for Java App Dropwizard UI Example
- Document Signature for Java Spring UI Example
Free Online App
Along with full-featured .NET library we provide simple, but powerful free Apps.
You are welcome to eSign PDF, Word, Excel, PowerPoint documents with free to use online GroupDocs Signature App.