Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save conholdate-docs-gists/e464529e174b5eaeca60a352341561cc to your computer and use it in GitHub Desktop.
Save conholdate-docs-gists/e464529e174b5eaeca60a352341561cc to your computer and use it in GitHub Desktop.
// 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);
}
// 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);
}
// 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);
}
@conholdate-docs-gists
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment