Created
August 16, 2022 12:55
-
-
Save conholdate-docs-gists/e464529e174b5eaeca60a352341561cc to your computer and use it in GitHub Desktop.
Remove watermark from photo | https://docs.conholdate.com/net/removing-watermark-from-photo/
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
// Constants.InDocumentPdf is an absolute or relative path to your document. Ex: @"C:\Docs\document.pdf" | |
using (Watermarker watermarker = new Watermarker(Constants.InDocumentPdf)) | |
{ | |
PossibleWatermarkCollection watermarks = watermarker.Search(new TextSearchCriteria(new Regex(@"someurl\.com"))); | |
for (int i = watermarks.Count - 1; i >= 0; i--) | |
{ | |
// Ensure that only hyperlinks will be removed. | |
if (watermarks[i] is HyperlinkPossibleWatermark) | |
{ | |
// Output the full url of the hyperlink | |
Console.WriteLine(watermarks[i].Text); | |
// Remove hyperlink from the document | |
watermarks.RemoveAt(i); | |
} | |
} | |
watermarker.Save(Constants.OutDocumentPdf); | |
} |
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
// Constants.InDocumentPdf is an absolute or relative path to your document. Ex: @"C:\Docs\document.pdf" | |
using (Watermarker watermarker = new Watermarker(Constants.InDocumentPdf)) | |
{ | |
PossibleWatermarkCollection possibleWatermarks = watermarker.Search(); | |
// Remove possible watermark at the specified index from the document. | |
possibleWatermarks.RemoveAt(0); | |
// Remove specified possible watermark from the document. | |
possibleWatermarks.Remove(possibleWatermarks[0]); | |
watermarker.Save(Constants.OutDocumentPdf); | |
} |
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
// Constants.InDocumentPdf is an absolute or relative path to your document. Ex: @"C:\Docs\document.pdf" | |
using (Watermarker watermarker = new Watermarker(Constants.InDocumentPdf)) | |
{ | |
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 watermarks = watermarker.Search(criteria); | |
watermarks.Clear(); | |
watermarker.Save(Constants.OutDocumentPdf); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Read the complete article: https://docs.conholdate.com/net/removing-watermark-from-photo/