Sign document with Text signature - advanced

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 TextSignOptions class to specify additional options for text signature to specify following signature appearance

Here are the steps to add Text signature into document with GroupDocs.Signature:

    • Create new instance of Signature class and pass source document path as a constructor parameter.
    • Instantiate the TextSignOptions object with all required additional options.
    • Call sign method of Signature class instance and pass TextSignOptions to it. 
    • Analyze SignResult result to check newly created signatures if needed.

This example shows how to add Text signature to document with advanced setup and analyzing result of method. See SignResult

Signature signature = new Signature("sample.pdf");
 
TextSignOptions options = new TextSignOptions("John Smith");
 
// set signature position
options.setLeft(100);
options.setTop(100);
 
// set signature rectangle
options.setWidth(100);
options.setHeight(30);
 
// set signature alignment
 
// when VerticalAlignment is set the Top coordinate will be ignored.
// Use Margin properties Top, Bottom to provide vertical offset
options.setVerticalAlignment(VerticalAlignment.Top);
 
// when HorizontalAlignment is set the Left coordinate will be ignored.
// Use Margin properties Left, Right to provide horizontal offset
options.setHorizontalAlignment(HorizontalAlignment.Right);
Padding padding = new Padding();
padding.setBottom(20);
padding.setRight(20);
options.setMargin(padding);
 
// adjust signature appearance
 
// setup signature border
Border border = new Border();
border.setColor(Color.GREEN);
border.setDashStyle(DashStyle.DashLongDashDot);
border.setTransparency(0.5);
border.setVisible(true);
border.setWeight(2);
options.setBorder(border);
 
// set text color and Font
options.setForeColor(Color.RED);
SignatureFont signatureFont = new SignatureFont();
signatureFont.setSize(12);
signatureFont.setFamilyName("Comic Sans MS");
options.setFont(signatureFont);
 
// setup background
Background background = new Background();
background.setColor(Color.LIGHT_GRAY);
background.setTransparency(0.5);
background.setBrush(new LinearGradientBrush(Color.GREEN, Color.DARK_GRAY, 0));
options.setBackground(background);
 
// set rotation
options.setRotationAngle(45);
 
// set alternative signature implementation on document page
options.setSignatureImplementation(TextSignatureImplementation.Image);
 
 
 
// set up shadow options for text
TextShadow shadow = new TextShadow();
shadow.setColor(Color.ORANGE);
shadow.setAngle(135);
shadow.setBlur(5);
shadow.setDistance(4);
shadow.setTransparency(0.2);
 
//add text shadow to signature extensions
options.getExtensions().add(shadow);
 
// sign document to file
SignResult signResult = signature.sign("signed.pdf", 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());
}

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.