Sign document with Barcode signature - advanced

GroupDocs.Signature provides BarcodeSignOptions class to specify additional options for Barcode signature to specify following signature appearance

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

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

This example shows how to add Barcode signature to document. See SignResult 

// 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
    signOptions.setLeft(100);
    signOptions.setTop(100);
    // when VerticalAlignment is set the Top coordinate will be ignored.
    // Use Margin properties Top, Bottom to provide vertical offset
    signOptions.setVerticalAlignment(VerticalAlignment.Top);
            // when HorizontalAlignment is set the Left coordinate will be ignored.
            // Use Margin properties Left, Right to provide horizontal offset
    signOptions.setHorizontalAlignment(HorizontalAlignment.Right);
    Padding padding = new Padding();
    padding.setLeft(20);
    padding.setTop(20);
    signOptions.setMargin(padding);
            // adjust signature appearance
            // setup signature border
    Border border = new Border();
    border.setColor(Color.GREEN);
    border.setDashStyle(DashStyle.DashLongDashDot);
    border.setWeight(2);
    border.setTransparency(0.5);
    border.setVisible(true);
    signOptions.setBorder(border);    
            // set text color and Font
    signOptions.setForeColor(Color.RED);
    SignatureFont font = new SignatureFont();
    font.setSize(12);
    font.setFamilyName("Comic Sans MS");
    signOptions.setFont(font);             
    // specify position of text with barcode line
    signOptions.setCodeTextAlignment(CodeTextAlignment.Above);
            // setup background
    Background background = new Background();
    background.setColor(Color.GREEN);
    background.setTransparency(0.5);
    background.setBrush(new LinearGradientBrush(Color.GREEN, Color.DARK_GRAY,0));
    signOptions.setBackground(background);                    
    
    // sign document   
    ignResult signResult = signature.sign("SampleSigned.docx", signOptions);
    // 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:

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.

Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.