Batch Watermarking with Duplicate-Safe Processing
Leave feedback
On this page
Overview
Many enterprises need to brand or protect thousands of documents—PDFs, Word files, presentations, and spreadsheets—on a regular basis. This sample ships with four document types (DOCX, PDF, XLSX, PPTX) so every pipeline mode is demonstrated across real‑world formats. Performing this manually is error‑prone and time‑consuming, and re‑running a batch job can unintentionally create duplicate watermarks. This use‑case shows how to apply text and logo watermarks in bulk while keeping the process duplicate-safe, so running the job multiple times never produces redundant marks. The solution leverages GroupDocs.Watermark for .NET, which abstracts the heavy lifting of format handling, searchable watermark objects, and smart replacement logic.
Prerequisites
.NET 6.0 or later installed on the development machine.
A valid GroupDocs.Watermark license file (temporary or permanent). The sample falls back to evaluation mode if the file is missing, but a licensed build removes evaluation watermarks.
Basic familiarity with C# console applications and file‑system operations.
Installation
# Clone the sample repositorygit clone https://github.com/groupdocs-watermark/batch-watermark-pipeline-using-groupdocs-watermark-dotnet.git
cd GroupDocs.Watermark-for-.NET/net/sample-project
# Add the Watermark library to the projectdotnet add package GroupDocs.Watermark
# Restore and build the solutiondotnet restore
dotnet build
The commands above set up a ready‑to‑run console app that demonstrates the complete batch pipeline.
Program.cs holds isolated methods for licensing, folder scanning, text watermarking, logo watermarking, smart duplicate checks, and logo replacement. Each method is small enough to be understood in isolation yet works together to form the end‑to‑end pipeline.
Usage Example
Below is a concise walk‑through that ties the helper methods together. Only the essential parts of each method are shown; the full source lives in Program.cs.
Step 1 – Load the License
try{varlicense=newLicense();license.SetLicense("./GroupDocs.Watermark.lic");Console.WriteLine("License applied.");}catch{Console.WriteLine("Running in evaluation mode – license not found.");}
The snippet creates a License instance and points it at a local .lic file. If the file cannot be located, the catch block prevents a crash and lets the demo continue in evaluation mode.
The TextSearchCriteria checks whether the exact phrase CONFIDENTIAL already exists. If it does, the file is skipped, guaranteeing that the batch can be re‑executed safely.
An image watermark is tiled across every page, using the same rotation and opacity as the text watermark. The example works for PDFs, Office files, and common image formats.
Two complementary image‑search strategies (DCT hash for precision, histogram for tolerance) locate the old corporate logo in both Office documents and PDF artifacts. Matching watermarks are overwritten with the new logo bytes, enabling seamless re‑branding.
Note
💡 Tip: Run the three steps sequentially (text → logo → replace) to simulate a full migration workflow.
Notes
Evaluation mode adds a subtle watermark to output files; obtain a proper license to remove it.
PDF artifacts must be added with PdfArtifactWatermarkOptions (as shown in the SeedOldLogoSamples helper) for the logo to become searchable.
The sample writes all processed files to ./Output. Ensure the folder exists or let the code create it automatically.
Large batches benefit from parallelism; the examples are deliberately single‑threaded for clarity.