Locating signature with different alignments

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Signature MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-signature -- dnx GroupDocs.Signature.Mcp --yes
Folders, licensing and more →

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");
            options.setWidth(qrWidth);
            options.setHeight(qrHeight);
            // set signature alignment
            options.setHorizontalAlignment(horizontalAlignment);
            options.setVerticalAlignment(verticalAlignment);
            options.setMargin(new Padding(5));
            listOptions.add(options);
        }
    }
}
// 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 Java 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.