Delete Barcode signatures from documents

Overview

GroupDocs.Signature provides BarcodeSignature class to manipulate barcode signatures and delete them from the documents over Delete method.
Please be aware that Delete method modifies the same document that was passed to constructor of Signature class.

How to delete Barcode signature from the document

Here are the steps to delete Barcode signature from the document with GroupDocs.Signature:

This example shows how to delete Barcode signature that was found using Search method.

  const filePath = Constants.SAMPLE_PDF_SIGNED; 
  const fileName = path.basename(filePath);

  const outputDirectory = path.join(Constants.OutputPath, 'DeleteBarcode');
  if (!fs.existsSync(outputDirectory)) {
    fs.mkdirSync(outputDirectory, { recursive: true });
  }

  // Copy source file since the delete method works with the same Document
  const outputFilePath = path.join(outputDirectory, fileName);

  fs.copyFileSync(filePath, outputFilePath);

  const signature = new signatureLib.Signature(outputFilePath);

  const options = new signatureLib.BarcodeSearchOptions();

  // Search for Barcode signatures in the document
  const signatures =  signature.search(signatureLib.BarcodeSignature.class, options).toArray();
  if (signatures.length > 0) {
     const barcodeSignature = signatures[0];
     const isDeleted = signature.delete(outputFilePath, barcodeSignature);
  
     const barcodeText = barcodeSignature.getText();
     const encodeTypeName = barcodeSignature.getEncodeType().getTypeName();
  
     if (isDeleted) {
         console.log(
             `Signature with Barcode '${barcodeText}' and encode type '${encodeTypeName}' was successfully deleted from the document '${fileName}'.`
         );
     } else {
         console.log(
             `Failed to delete the signature! Barcode '${barcodeText}' with encode type '${encodeTypeName}' was not removed from the document '${fileName}'.`
         );
     }
  }

More resources

GitHub Examples

You may easily run the code above and see the feature in action in our GitHub examples:

Free Online Apps

Along with the full-featured .NET library, we provide simple but powerful free online apps.

To sign PDF, Word, Excel, PowerPoint, and other documents you can use the online apps from the GroupDocs.Signature App Product Family.