Locating signature with stretch mode

GroupDocs.Signature provides ability to stretch signature area along page width or height. Use enumeration StretchMode contains following values

  • None - no stretch will be applied 
  • PageWidth -  to stretch signature area along page width
  • PageHeight - to stretch signature area along page height
  • PageArea - to stretch signature area along page width and height

Here are the steps to use stretch mode with adding text or images signatures into document with GroupDocs.Signature:

Locate Signature Area with Stretch Mode

This example shows how to locate signature with stretch mode.

// instantiating the signature object
final Signature signature = new Signature("sample.pdf");
 
// define several signature options of different types and settings
TextSignOptions textOptions = new TextSignOptions("This is test message");
textOptions.setAllPages(true);
textOptions.setVerticalAlignment(VerticalAlignment.Top);
textOptions.setMargin(new Padding(50));
textOptions.setStretch(StretchMode.PageWidth);
 
BarcodeSignOptions barcodeOptions = new BarcodeSignOptions("123456");
barcodeOptions.setAllPages(true);
barcodeOptions.setEncodeType(BarcodeTypes.Code128);
barcodeOptions.setVerticalAlignment(VerticalAlignment.Bottom);
barcodeOptions.setMargin(new Padding(50));
barcodeOptions.setStretch(StretchMode.PageWidth);
 
ImageSignOptions imageOptions = new ImageSignOptions();
imageOptions.setAllPages(true);
imageOptions.setStretch(StretchMode.PageHeight);
imageOptions.setHorizontalAlignment(HorizontalAlignment.Right);
imageOptions.setImageFilePath("image.png");
 
// define list of signature options
List<SignOptions> listOptions = new ArrayList<SignOptions>();
listOptions.add(textOptions);
listOptions.add(barcodeOptions);
listOptions.add(imageOptions);
// 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.