In many cases, PDF documents come with watermarks that may obscure important content or detract from the presentation. Whether you’re dealing with text, images, or even hyperlink-based watermarks, you can easily remove them. In this post, we will guide you through two common scenarios: removing general watermarks from a PDF and specifically removing hyperlink watermarks in C#.
Remove Watermarks from PDF - C# API Installation
To remove watermarks from a PDF document, you need to install Conholdate.Total for .NET API in your environment. Download the DLL file or use the NuGet installation command below:
PM> NuGet\Install-Package Conholdate.Total
Remove Watermark from PDF in C#
To remove watermarks from a PDF document, we will use the Watermarker class. This powerful tool allows you to search for and eliminate any watermarks present in the document.
- Load the PDF: We begin by loading the PDF document with the Watermarker class.
- Search for Watermarks: The Search method identifies potential watermarks present in the document.
- Remove the Watermark: The code then removes the watermark either by specifying its index (RemoveAt(0)) or directly passing the watermark object (Remove(possibleWatermarks[0])).
- Save the Document: Finally, the document is saved without the watermark.
Below is the code that demonstrates how to remove a watermark from a PDF using C#.
This approach is flexible and allows you to remove various types of watermarks, such as text or image-based watermarks, quickly and efficiently.
Remove Hyperlink Watermark from PDF in C#
Some PDF documents contain hyperlink watermarks, where the watermark consists of a clickable URL. These can be removed by specifically targeting hyperlinks. Below is an example of how you can search and remove hyperlink watermarks based on specific URL patterns.
- Search for Hyperlinks: This code first uses a TextSearchCriteria with a regular expression to find hyperlinks matching a specified URL (e.g., “someurl.com”).
- Filter Hyperlinks: It checks whether the identified watermark is a hyperlink (HyperlinkPossibleWatermark).
- Remove Hyperlink: If it’s a hyperlink, the code outputs its URL to the console and removes the hyperlink from the document.
- Save the Document: The updated PDF document is saved without the hyperlink watermarks.
This method is especially useful if you need to clean up documents that contain URLs as watermarks, ensuring that only the specified hyperlink watermarks are removed.
Free Evaluation License
You can get a free temporary license to evaluate different features without any limitations.
Wrapping Up
Whether you’re dealing with general text or image-based watermarks or more specific hyperlink watermarks, the API offers a powerful and flexible solution. You can quickly identify and remove unwanted watermarks, ensuring your PDFs are clean and professional. The process is simple, allowing for precise control over the type of watermark removed, whether by index or URL pattern, giving you the ability to tailor the document exactly to your needs. In case of any ambiguities, please reach out to us at forum.