GroupDocs.Signature provides the BarcodeSignature class to manipulate barcode signatures’ location, size, and textual content. Please be aware 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 Barcode 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.
Select from the list the BarcodeSignature 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 Barcode signature that was found using Search method.
// The path to the documents directory.constfilePath=Constants.SAMPLE_PDF_SIGNED;constfileName=path.basename(filePath);// Copy source file since the update method works with the same documentconstoutputFilePath=path.join(Constants.OutputPath,'UpdateBarcode',fileName);constdir=path.dirname(outputFilePath);if(!fs.existsSync(dir)){fs.mkdirSync(dir,{recursive:true});}// Initialize Signature instanceconstsignature=newsignatureLib.Signature(filePath);// Initialize BarcodeSearchOptionsconstoptions=newsignatureLib.BarcodeSearchOptions();// Search for barcode signatures in the documentconstsignatures=signature.search(signatureLib.BarcodeSignature.class,options).toArray();if(signatures.length>0){constbarcodeSignature=signatures[0];barcodeSignature.setLeft(100);barcodeSignature.setTop(100);// Update the barcode signature in the documentconstresult=signature.update(outputFilePath,barcodeSignature);if(result){console.log(`\nSignaturewithBarcode'${barcodeSignature.getText()}'andencodetype'${barcodeSignature.getEncodeType().getTypeName()}'wasupdatedinthedocument['${fileName}'].`);}else{console.log(`\nSignaturewasnotupdatedinthedocument!SignaturewithBarcode'${barcodeSignature.getText()}'andencodetype'${barcodeSignature.getEncodeType().getTypeName()}'wasnotfound!`);}}
More resources
GitHub Examples
You may easily run the code above and see the feature in action in our GitHub examples: