Add text or image watermark

GroupDocs.Watermark allows to add watermarks and save resultant document. It is capable to add watermark to image or documents. Full list of supported document formats can be found here. You may add text and image watermarks to the documents from local disk and from streams.

Add a text watermark

The following example demostrates how to add a TextWatermark to a local document:

  • Create a watermarker for the local file (line 1);
  • Create a watermark with text and font (line 3);
  • Set the watermark color, horizontal and vertical alignments (lines 4-6);
  • Add the watermark to the document (line 7);
  • Save the document to the new file (line 8).

BasicUsage.AddATextWatermark

// Constants.InDocumentPdf is an absolute or relative path to your document. Ex: @"C:\Docs\document.pdf"
using (Watermarker watermarker = new Watermarker(Constants.InDocumentPdf))
{
    TextWatermark watermark = new TextWatermark("top secret", new Font("Arial", 36));
    watermark.ForegroundColor = Color.Red;
    watermark.HorizontalAlignment = HorizontalAlignment.Center;
    watermark.VerticalAlignment = VerticalAlignment.Center;
    watermarker.Add(watermark);
    watermarker.Save(Constants.OutDocumentPdf);
}

Add an image watermark

The following example demonstrates how to add an ImageWatermark to a document from a stream:

  • Create a watermarker for the file stream (line 1);
  • Create a image watermark from the local image file (line 3);
  • Set the watermark horizontal and vertical alignments (lines 5, 6);
  • Add the watetmark to the document (line 7);
  • Save the document to the new file (line 10).

BasicUsage.AddAnImageWatermark

// Constants.InDocumentXlsx is an absolute or relative path to your document. Ex: @"C:\Docs\document.xlsx"
using (FileStream stream = File.Open(Constants.InDocumentXlsx, FileMode.Open, FileAccess.ReadWrite))
{
    using (Watermarker watermarker = new Watermarker(stream))
    {
        using (ImageWatermark watermark = new ImageWatermark(Constants.LogoPng))
        {
            watermark.HorizontalAlignment = HorizontalAlignment.Center;
            watermark.VerticalAlignment = VerticalAlignment.Center;
            watermarker.Add(watermark);
        }

        watermarker.Save(Constants.OutDocumentXlsx);
    }
}

More resources

Advanced usage topics

To learn more about document watermarking features and get familiar how to manage watermarks and more, please refer to the advanced usage section.

GitHub examples

You may easily run the code above and see the feature in action in our GitHub examples:

Free online document watermarking App

Along with full featured .NET library we provide simple, but powerful free Apps.

You are welcome to add watermark to PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX, Emails and more with our free online Free Online Document Watermarking App.