How To Remove Watermark from PDF Documents Using C#
Tags: csharp, dotnet, beginners
Published: 2019-11-19 11:42:47

This post was originally posted on [my blog](https://blog.groupdocs.com/2019/11/06/remove-watermark-from-pdf/)

If you are looking to delete watermarks from your single or bulk of PDF documents. This article is a good learning source for the c# programming developers.
## Removing watermarks from PDF documents and its importance
Watermarks importance is high for all those who intends to ascertain their copyrights if in case their data gets copied somewhere. The information contained within the watermark designates the authority of the owner and prevents another users from deleting the copyright. But at times, it really becomes a troublesome for many users out there as you need the information on an urgent basis.

A variety of utilities, paid or free online tools might be available to get your problem resolved. The following sections show that how  _C# Programming_  developers can do it via their coding editors.
## Delete watermark using C# language

[The GroupDocs.Watermark](https://products.groupdocs.com/watermark)  is an API to perform watermarking operations on the images or the documents of different  [file formats](https://wiki.fileformat.com/home/). If you are making a  _watermark remover app_, It provides you some useful ways to  [remove all watermarks](https://docs.groupdocs.com/display/watermarknet/Removing+Found+Watermarks#RemovingFoundWatermarks-RemoveWatermark),  [remove watermark with particular text formatting](https://docs.groupdocs.com/display/watermarknet/Removing+Found+Watermarks#RemovingFoundWatermarks-RemoveWatermarkwithParticularTextFormatting)  or  [remove hyperlink watermarks](https://docs.groupdocs.com/display/watermarknet/Removing+Found+Watermarks#RemovingFoundWatermarks-RemoveHyperlinkWatermarks)

Lets learn how a  _C# developer_  can  _remove watermark from PDF_  using  [GroupDocs.Watermark for .NET](https://products.groupdocs.com/watermark)  API.

## Remove watermark with particular text formatting

The API also enables you to search and remove the watermarks on the basis of some particular text formatting. You can provide a search criterion containing font name, size, color etc and the API will find the watermarks with matching properties. 
Following code snippet shows how to search and remove watermarks with a particular text formatting.
```csharp
// 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);
}
```
## Remove all occurrences of watermarks from a PDF document

The  [GroupDocs.Watermark](https://docs.groupdocs.com/display/watermarknet/)  API enables you to easily find and remove a particular watermark from a document. Following code serves this purpose.

```csharp
// 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);
}
```
## Remove hyperlink watermarks

GroupDocs.Watermark API allows you to search and remove hyperlinks in a document of any supported format. Following code sample shows how to find and remove hyperlinks with a particular URL from a document.
```csharp
// 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);
}
```
The complete ready to run code sample is available on [GitHub](https://github.com/groupdocs-watermark/).