Clear watermarks

Removing existing watermarks is another powerful feature of the GroupDocs.Watermark library. It allows searching and then removing text or image watermarks from a wide range of supported documents. Removing watermarks is possible for some of the supported formats. To learn whether it is available for your format, check Supported formats.

Note
Updating of watermarks is not allowed in evaluation mode. Please set up a license as described in Licensing and evaluation.

Deleting text watermarks

To search and remove text watermarks follow next sample:

const groupdocs.watermark = require('@groupdocs/groupdocs.watermark')

function removeTextWatermarks() {
    // Create an instance of Watermarker
    const watermarker = new groupdocsWatermark.Watermarker('sample.pdf');

    // Create a TextSearchCriteria instance
    const criteria = new groupdocsWatermark.TextSearchCriteria('test', false);
    const watermarks = watermarker.search(criteria);

    // Remove found text fragments
    watermarks.clear();

    // Save changes
    watermarker.save('result.pdf');

    // Close watermarker
    watermarker.close();
}

Deleting image watermarks

To search and remove image watermarks within the document:

const groupdocs.watermark = require('@groupdocs/groupdocs.watermark')

function removeImageWatermarks() {
  // Create watermarker
  const watermarker = new groupdocsWatermark.Watermarker('sample.docx');

  // Initialize search criteria with the image
  const imageSearchCriteria = new groupdocsWatermark.ImageDctHashSearchCriteria("logo.png");

  // Set maximum allowed difference between images
  imageSearchCriteria.setMaxDifference(0.9);

  // Search for possible watermarks matching the criteria
  const watermarks = watermarker.search(imageSearchCriteria);

  console.log(`Found ${watermarks.getCount()} possible watermark(s).`);

    // Remove found text fragments
    watermarks.clear();

    // Save changes
    watermarker.save('result.docx');

    // Close watermarker
    watermarker.close();
}

Run the program. All found occurrences of image watermarks will be deleted.