Related blog post: Remove Watermarks from PDF in Java
Last active
April 9, 2022 13:19
-
-
Save GroupDocsGists/216355e47a4da58e9f874d4fafbf5bb5 to your computer and use it in GitHub Desktop.
Remove watermarks from PDF File and other documents in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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