Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Remove Watermarks from Documents using Java
Remove Watermarks from Documents using Java
1. Remove All Watermarks from PDF using Java
2. Remove Text Watermarks
3. Remove Watermark with Particular Text Formatting
4. Remove Image Watermarks
// Create an instance
Watermarker watermarker = new Watermarker("C:\\Files\\sample.pdf");
// Search all possible watermarks
PossibleWatermarkCollection possibleWatermarks = watermarker.search();
// Remove all found watermarks
possibleWatermarks.clear();
// Save updated file
watermarker.save("C:\\Files\\output.pdf");
watermarker.close();
// Create an instance
Watermarker watermarker = new Watermarker("C:\\Files\\sample.pdf");
// Search all possible watermarks
PossibleWatermarkCollection possibleWatermarks = watermarker.search();
// Remove all image watermarks
for (int i = possibleWatermarks.getCount() - 1; i >= 0; i--)
{
if(possibleWatermarks.get_Item(i).getImageData() != null)
{
possibleWatermarks.removeAt(i);
}
}
// Save updated document
watermarker.save("C:\\Files\\output.pdf");
watermarker.close();
// Create an instance
Watermarker watermarker = new Watermarker("C:\\Files\\sample.pdf");
// Search all possible watermarks
PossibleWatermarkCollection possibleWatermarks = watermarker.search();
// Remove all found watermarks
for (int i = possibleWatermarks.getCount() - 1; i >= 0; i--)
{
if(possibleWatermarks.get_Item(i).getText() != null && possibleWatermarks.get_Item(i).getText() != "")
{
possibleWatermarks.removeAt(i);
}
}
// Save updated document
watermarker.save("C:\\Files\\output.pdf");
watermarker.close();
// Create an instance
Watermarker watermarker = new Watermarker("C:\\Files\\sample.pdf");
// Search possible watermarks
PossibleWatermarkCollection possibleWatermarks = watermarker.search();
// Remove all found watermarks
for (int i = possibleWatermarks.getCount() - 1; i >= 0; i--)
{
possibleWatermarks.removeAt(i);
}
// Save updated document
watermarker.save("C:\\Files\\output.pdf");
watermarker.close();
// Create an instance
Watermarker watermarker = new Watermarker("C:\\Files\\sample.pdf");
// Define text formatting search criteria
TextFormattingSearchCriteria criteria = new TextFormattingSearchCriteria();
criteria.setFontName("Arial");
criteria.setMinFontSize(19);
criteria.setMaxFontSize(42);
criteria.setFontBold(false);
// Search possible watermarks
PossibleWatermarkCollection watermarks = watermarker.search(criteria);
watermarks.clear();
// Save updated document
watermarker.save("C:\\Files\\output.pdf");
watermarker.close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment