GroupDocs.Signature provides the TextSignature class to manipulate text signatures’ location, size, and textual content. Please note that the Update method modifies the same document that was passed to the constructor of the Signature class.
Here are the steps to update a Text signature in the document with GroupDocs.Signature:
Create a new instance of the Signature class and pass the source document path as a constructor parameter.
Instantiate the TextSearchOptions object with the desired properties.
Select from the list the TextSignature object(s) that should be updated.
Call the Signature object’s Update method and pass one or several signatures to it.
This example shows how to update a Text signature that was found using the Search method.
// The path to the documents directory.constfilePath=Constants.SAMPLE_SIGNED_MULTI;constfileName=path.basename(filePath);// Copy source file since the update method works with the same documentconstoutputFilePath=path.join(Constants.OutputPath,'UpdateText',fileName);constdir=path.dirname(outputFilePath);if(!fs.existsSync(dir)){fs.mkdirSync(dir,{recursive:true});}// Initialize Signature instanceconstsignature=newsignatureLib.Signature(filePath);// Initialize TextSearchOptionsconstoptions=newsignatureLib.TextSearchOptions();// Search for text signatures in the documentconstsignatures=signature.search(signatureLib.TextSignature.class,options).toArray();if(signatures.length>0){consttextSignature=signatures[0];// Change Text propertytextSignature.setText('JohnWalkman');// Change positiontextSignature.setLeft(textSignature.getLeft()+50);textSignature.setTop(textSignature.getTop()+50);// Change size. Please note not all documents support changing signature sizetextSignature.setWidth(200);textSignature.setHeight(100);// Update the text signature in the documentconstresult=signature.update(outputFilePath,textSignature);if(result){console.log(`\nSignaturewithText'${textSignature.getText()}'wasupdatedinthedocument['${fileName}'].`);}else{console.log(`\nSignaturewasnotupdatedinthedocument!SignaturewithText'${textSignature.getText()}'wasnotfound!`);}}
More resources
GitHub Examples
You may easily run the code above and see the feature in action in ourΒ GitHub examples: