Accusoft.PdfXpress5.Net
Add Watermark to a PDF document
Send Feedback
PDF Xpress 5 for .NET - User Guide > How To > Modify PDF Document Content > Add Watermark to a PDF document

Glossary Item Box

You can add source-based watermarks and text watermarks to a PDF. Source-based means the source of the watermark is another PDF.

To add a source-based watermark to a PDF, do the following:

  1. Create a PDFXpress object and initialize it.
  2. Create a Document object from an existing PDF file.
  3. Create a Document object from an existing PDF file to be used as the watermark source.
  4. Create a PageArtifactOptions object.
  5. Set the PageArtifactOptions:
    • ArtifactType - specifies the type of watermark, in this case SourceWatermark.
    • Opacity – we set this to .5, to make the watermark translucent
    • PageList – we set this to specify to what pages the watermark will be added
    • SourceDocument – we set this to our source PDF watermark
    • SourcePageNumber – we set this to 0, to specify the first page
  6. Call AddWatermark() on the Document object to add the watermark.
  7. Create a SaveOptions object.
  8. Call Save() on the Document object to save the watermarked pdf.
C# Example Copy Code
using System;
using Accusoft.PdfXpressSdk;
namespace PDFWatermark
{
    class Watermark
    {
        static void Main(string[] args)
        {
            using (PdfXpress pdf = new PdfXpress())
            {
                pdf.Initialize(@"C:\Users\Public\Documents\Accusoft\PDFXpress\v5.0\Support\Font", 
                               @"C:\Users\Public\Documents\Accusoft\PDFXpress\v5.0\Support\CMap");
                using (Document doc = new Document(pdf, "C:\\myfile.pdf"))
                {
                    using (Document sourceDoc = new Document(pdf, "C:\\source.pdf"))
                    {
                        //create the page artifact options
                        PageArtifactOptions po = new PageArtifactOptions();
                        po.ArtifactType = TypeOfArtifact.SourceWatermark;
                        po.Opacity = .5;
                        PageRange pageRange = new PageRange();
                        pageRange.PageCount = 1;
                        pageRange.StartPageNumber = 0;
                        PageList pageList = new PageList();
                        pageList.Add(pageRange);
                        po.PageList = pageList;
                        po.SourceDocument = sourceDoc;
                        po.SourcePageNumber = 0;                        
                        //add the watermark
                        doc.AddWatermark(po);
                        //set the save options
                        SaveOptions so = new SaveOptions();
                        so.Filename = "C:\\watermarked.pdf";
                        so.Overwrite = true;
                        so.Linearized = true;
                        //save the document
                        doc.Save(so);
                    }
                }
            }
        }
    }
}
©2012. Accusoft Corporation. All Rights Reserved.