A digital watermark is any auxiliary data embedded into a document used for subsequent identification. Watermarks may provide contextual support to an author's content, but are otherwise independent of that content. For example, stamping a page as "DRAFT" or "CONFIDENTIAL" imparts meaning beyond any text or drawings present on that page.
PDF documents may express a digital watermark using any of the following techniques:
- Annotations: An interactive object associated with a location on the page that displays text or an image. A variety of types may be used including Text, Free text, Rubber stamp. Watermark annotations may be used to print at a fixed position and size on a page regardless of the dimensions of the printed page.
- Page Graphics: Graphics may include text with specific style information and color, vector line art, sampled images or shading patterns. Content representing a watermark is inserted directly into the page's content stream, possibly indistinguishable from the original content. Graphics specifically intended for watermarks may be indicated using Optional Content Groups.
- Optional Content Groups (OCG): Collections of graphics in a PDF document can be selectively drawn or hidden by document authors or consumers. An OCG can indicate its graphics are intended as a watermark for printing.
- Pagination Artifacts. Tagged PDF documents distinguish between original content and artifacts of the layout process, including pagination artifacts such as header, footers, page numbers. Content may be specifically designated to be a watermark.
Each of these techniques can be accomplished using ImageGear, with varying complexity and completeness. See the following subsections:
Annotations
Annotations are added to PDF pages by using the ImageGear.ART namespace, which supports a subset of available PDF annotations. Refer to PDF Annotations for the mapping used with PDF annotations.
ImageGear .NET does not export ART Marks to PDF Watermark annotations. Apps that require explicit PDF Watermark annotation support may use the basic object classes to create a PDF Watermark annotation object and appearance streams, as outlined in the PDF Reference under topic "Watermark Annotations".
The following sample code demonstrates creating a Text ART mark and exporting to a PDF page as a FreeText annotation:
PDF support needs to be initialized first for this snippet to work. To get familiar with initializing IGNET, initializing PDF support, loading a PDF, saving a PDF, and terminating PDF support, try any one of the
tutorials.
See the PDF Reference topic "Annotations" for additional information.
Page Graphics
Watermarks expressed as PDF page graphics are added using the ImageGear.Formats.PDF namespace. This namespace provides classes for content editing modeled after graphics objects and operators described in the PDF Reference.
The following snippet demonstrates placing a 24-bpp RGB bitmap at the bottom left corner of a PDF page:
PDF support needs to be initialized first for this snippet to work. To get familiar with initializing IGNET, initializing PDF support, loading a PDF, saving a PDF, and terminating PDF support, try any one of the
tutorials.
Adjustments are required to successfully add images utilizing other pixel formats and color spaces in accordance to the image XObject discussion in the PDF reference.
See the PDF Reference topic "Graphics" for additional information.
See ImGearPDFFixedMatrix Class for information about defining a transformation matrix.
Optional Content Groups
Watermark optional content can be added to PDF pages using the ImageGear.Formats.PDF namespace, which provides classes for layer management.
Refer to Containers, Dictionaries, and Layers for guidance on using the ImageGear.Formats.PDF namespace to manage watermarks with Optional Content Groups (OCG).
To designate a watermark intended for printing, add an Optional Content Print Usage dictionary with Subtype name "Watermark" to that OCG, represented with an ImGearPDFLayer object:
C# |
Copy Code |
// Create Print Usage dictionary
ImGearPDFBasDict igPrintUsageDict = new ImGearPDFBasDict( igPDFDocument, false, 2 );
igPrintUsageDict.PutName( new ImGearPDFAtom("Subtype"), false, new ImGearPDFAtom( "Watermark" ));
igPrintUsageDict.PutName( new ImGearPDFAtom("PrintState"), false, new ImGearPDFAtom( "ON" ));
// Add Print Usage dictionary to OCG group named "WatermarkLayer"
ImGearPDFLayer igWatermarkLayer = igPDFDocument.CreateLayer( "WatermarkLayer" );
igWatermarkLayer.SetUsageInfo( new ImGearPDFAtom("Print"), igPrintUsageDict ); |
See the PDF Reference topic "Making Graphical Content Optional" for additional information.
Pagination Artifacts
Watermarks expressed as Pagination Artifacts can be added using the ImageGear.Formats.PDF namespace, which provides classes to create a marked-content sequence in accordance with the PDF Reference.
See the PDF Reference topic "Real Content and Artifacts" for additional information.