Skip to content

Instantly share code, notes, and snippets.

@GroupDocsGists
Last active April 9, 2022 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GroupDocsGists/216355e47a4da58e9f874d4fafbf5bb5 to your computer and use it in GitHub Desktop.
Save GroupDocsGists/216355e47a4da58e9f874d4fafbf5bb5 to your computer and use it in GitHub Desktop.
Remove watermarks from PDF File and other documents in Java
// Remove the watermarks from PDF & other Documents in Java
Watermarker watermarker = new Watermarker("filepath/document-with-watermarks.pdf");
PossibleWatermarkCollection possibleWatermarks = watermarker.search();
for (int i = 0 ; i < watermarks.getCount(); i++)
{
// Remove every watermark by mentioning the index within the document.
possibleWatermarks.removeAt(i);
}
watermarker.save("filepath/no-watermarks.pdf");
watermarker.close();
// Remove Hyperlink watermarks from PDF in Java
Watermarker watermarker = new Watermarker("path/watermark-document.pdf");
PossibleWatermarkCollection watermarks = watermarker.search(new TextSearchCriteria(Pattern.compile("someurl.com")));
for (int i = 0 ; i < watermarks.getCount(); i++)
{
if (HyperlinkPossibleWatermark.class.isInstance(watermarks.get_Item(i)))
{
System.out.println(watermarks.get_Item(i).getText());
watermarks.removeAt(i);
}
}
watermarker.save("path/no-hyperlink-watermarks.pdf");
// Remove watermarks with specific text formatting from a PDF in Java
Watermarker watermarker = new Watermarker("path/watermarks.pdf");
TextFormattingSearchCriteria criteria = new TextFormattingSearchCriteria();
criteria.setForegroundColorRange(new ColorRange());
criteria.getForegroundColorRange().setMinHue(-5);
criteria.getForegroundColorRange().setMaxHue(10);
criteria.getForegroundColorRange().setMinBrightness(0.01f);
criteria.getForegroundColorRange().setMaxBrightness(0.99f);
criteria.setBackgroundColorRange(new ColorRange());
criteria.getBackgroundColorRange().setEmpty(true);
criteria.setFontName("Arial");
criteria.setMinFontSize(19);
criteria.setMaxFontSize(42);
criteria.setFontBold(true);
PossibleWatermarkCollection watermarks = watermarker.search(criteria);
watermarks.clear();
watermarker.save("path/removed-watermarks.pdf");
watermarker.close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment