Related blog post: Remove Watermarks from PDF files using C#
Last active
April 9, 2022 12:59
-
-
Save GroupDocsGists/4fa618502d15fc884614db7d7601ec53 to your computer and use it in GitHub Desktop.
Remove watermarks from PDF File and other documents using C# .NET
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 using C# | |
using (Watermarker watermarker = new Watermarker("filepath/documentWithWatermarks.pdf")) | |
{ | |
PossibleWatermarkCollection possibleWatermarks = watermarker.Search(); | |
// Remove every watermark by mentioning the index within document. | |
for (int i = 0; i < possibleWatermarks.Count; i++) | |
{ | |
possibleWatermarks.RemoveAt(i); | |
} | |
watermarker.Save("filepath/no-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 Hyperlink watermarks from PDF using C# | |
using (Watermarker watermarker = new Watermarker("path/Hyperlink-Watermarks.pdf")) | |
{ | |
PossibleWatermarkCollection watermarks = watermarker.Search(new TextSearchCriteria(new Regex(@"someurl\.com"))); | |
for (int i = 0 ; i < watermarks.Count; i++) | |
{ | |
if (watermarks[i] is HyperlinkPossibleWatermark) | |
{ | |
Console.WriteLine("Removing: " + watermarks[i].Text); | |
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 the watermarks from PDF & other Documents using C# | |
using (Watermarker watermarker = new Watermarker("filepath/documentWithWatermarks.pdf")) | |
{ | |
PossibleWatermarkCollection possibleWatermarks = watermarker.Search(); | |
// Remove watermark at the specified index from the document. | |
possibleWatermarks.RemoveAt(0); | |
// Remove specified watermark from the document. | |
possibleWatermarks.Remove(possibleWatermarks[0]); | |
watermarker.Save("filepath/noWatermarks.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 using C# | |
using (Watermarker watermarker = new Watermarker("path/Watermarks.pdf")) | |
{ | |
TextFormattingSearchCriteria criteria = new TextFormattingSearchCriteria(); | |
criteria.ForegroundColorRange = new ColorRange(); | |
criteria.ForegroundColorRange.MinHue = -5; | |
criteria.ForegroundColorRange.MaxHue = 10; | |
criteria.ForegroundColorRange.MinBrightness = 0.01f; | |
criteria.ForegroundColorRange.MaxBrightness = 0.99f; | |
criteria.BackgroundColorRange = new ColorRange(); | |
criteria.BackgroundColorRange.IsEmpty = true; | |
criteria.FontName = "Arial"; | |
criteria.MinFontSize = 19; | |
criteria.MaxFontSize = 42; | |
criteria.FontBold = true; | |
PossibleWatermarkCollection possibleWatermarks = watermarker.Search(criteria); | |
possibleWatermarks.Clear(); | |
watermarker.Save("path/removed-watermarks.pdf"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment