Locating signature with different alignments

GroupDocs.Signature provides ability to align signature on page with horizontal and vertical alignment settings. Signature options that implement interface IAlignment contain following properties:

Here are the steps to align signature on page with GroupDocs.Signature:

  • Create a new instance of Signature class and pass source document path or stream as a constructor parameter.
  • Instantiate signature options (ImageSignOptions for example) with all required properties.
  • Set  setHorizontalAlignment with one of enumeration value to align signature along page width
  • Set  setVerticalAlignment with one of enumeration value to align signature along page height
  • Set  setMargin property with required offsetfrom page border
  • Set  setMarginMeasureType property with non default value if there is need to specify offset from page border in another measure units like millimeters and page percents (from 100% width and 100% height)
  • Call sign method of Signature class instance and pass the instance of signature options (ImageSignOptions for example) to it.

This example shows how to locate signature with different alignments.

// instantiating the signature object
final Signature signature = new Signature("sample.pdf");
// define qr-code size
int qrWidth = 100;
int qrHeight = 100;
// define list of options        
List<SignOptions> listOptions = new ArrayList<SignOptions>();
// walk through all alignment values to locate signature at all page alignment areas
for(int horizontalAlignment : HorizontalAlignment.getValues())
    for (int verticalAlignment : VerticalAlignment.getValues())
        if (verticalAlignment != VerticalAlignment.None && horizontalAlignment != HorizontalAlignment.None)
            QrCodeSignOptions options =  new QrCodeSignOptions("Left-Top");
            // set signature alignment
            options.setMargin(new Padding(5));
// sign document to file
SignResult signResult = signature.sign("signed.pdf", listOptions);
// 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());

More resources

GitHub Examples 

You may easily run the code above and see the feature in action in our GitHub examples:

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.