Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to remove watermark from documents
// configure the search criteria for image watermark
ImageSearchCriteria imageSearchCriteria = new ImageDctHashSearchCriteria("watermark.png");
// configure the search criteria for text watermark
TextSearchCriteria textSearchCriteria = new TextSearchCriteria("CONFIDENTIAL");
// combine the search criteria
SearchCriteria combinedSearchCriteria = imageSearchCriteria.or(textSearchCriteria);
// find possible watermarks
PossibleWatermarkCollection possibleWatermarks = doc.findWatermarks(combinedSearchCriteria);
import com.groupdocs.watermark.Document;
import com.groupdocs.watermark.ImageDctHashSearchCriteria;
import com.groupdocs.watermark.ImageSearchCriteria;
import com.groupdocs.watermark.PossibleWatermarkCollection;
import com.groupdocs.watermark.SearchCriteria;
import com.groupdocs.watermark.TextSearchCriteria;
Document doc = Document.load("watermarked.pdf");
// iterate through the collection and remove watermarks
while(possibleWatermarks.getCount()>0)
{
if (possibleWatermarks.get_Item(0).getImageData() != null)
{
possibleWatermarks.removeAt(0);
System.out.println("removed image watermark.");
}
else
{
possibleWatermarks.removeAt(0);
System.out.println("removed text watermark.");
}
}
Document doc = Document.load("watermarked.pdf");
// configure the search criteria for image watermark
ImageSearchCriteria imageSearchCriteria = new ImageDctHashSearchCriteria("watermark.png");
// configure the search criteria for text watermark
TextSearchCriteria textSearchCriteria = new TextSearchCriteria("CONFIDENTIAL");
// combine the search criteria
SearchCriteria combinedSearchCriteria = imageSearchCriteria.or(textSearchCriteria);
PossibleWatermarkCollection possibleWatermarks = doc.findWatermarks(combinedSearchCriteria);
// iterate through the collection and remove watermarks
while(possibleWatermarks.getCount()>0)
{
if (possibleWatermarks.get_Item(0).getImageData() != null)
{
possibleWatermarks.removeAt(0);
System.out.println("removed image watermark.");
}
else
{
possibleWatermarks.removeAt(0);
System.out.println("removed text watermark.");
}
}
doc.save("without_watermark.pdf");
doc.close();
doc.save("without_watermark.pdf");
doc.close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.