Learn about how many ways the Groupdocs.watermark can add watermarks in PDF documents.
XObjects
When add() method of Watermarker class is called, simple XObject is added to a PDF document.
Note
PDF Reference 1.7
An external object (commonly called an XObject) is a graphics object whose contents are defined by a self-contained content stream, separate from the content stream in which it is used. There are three types of external objects:
An image XObject represents a sampled visual image such as a photograph.
A form XObject is a self-contained description of an arbitrary sequence of graphics objects.
A PostScript XObject contains a fragment of code expressed in the PostScript page description language. PostScript XObjects are no longer recommended to be used.
Image XObject and Form XObject are used by GroupDocs.Watermark API to add ImageWatermark and TextWatermark respectively. XObjects are considered as a page real content, therefore, they are not removed by Adobe Acrobat during document sanitization.
Artifacts
Note
PDF Reference 1.7
The graphics objects in a document can be divided into two classes:
The real content of a document comprises objects representing material originally introduced by the document’s author.
Artifacts are graphics objects that are typically not part of the author’s original content but rather are generated by the PDF producer application in the course of pagination, layout, or other strictly mechanical processes. Artifacts may also be used to describe areas of the document where the author uses a graphical background, with the goal of enhancing the visual experience. In such a case, the background is not required for understanding the content.
According to artifact definition, the watermark can be represented by an artifact in a PDF document. The following example shows how artifact watermark can be added to a document with GroupDocs.Watermark using PdfArtifactWatermarkOptions.
advanced_usage.add_watermarks_to_pdf.PdfAddArtifactWatermark
PdfLoadOptionsloadOptions=newPdfLoadOptions();// Specify an absolute or relative path to your document. Ex: "C:\\Docs\\document.pdf"
Watermarkerwatermarker=newWatermarker("document.pdf",loadOptions);PdfArtifactWatermarkOptionsoptions=newPdfArtifactWatermarkOptions();// Add text watermark
TextWatermarktextWatermark=newTextWatermark("This is an artifact watermark",newFont("Arial",8));textWatermark.setHorizontalAlignment(HorizontalAlignment.Right);watermarker.add(textWatermark,options);// Add image watermark
ImageWatermarkimageWatermark=newImageWatermark("logo.bmp");watermarker.add(imageWatermark,options);imageWatermark.close();watermarker.save("document.pdf");watermarker.close();
Annotations
Note
PDF Reference 1.7
An annotation associates an object such as a note, sound, or movie with a location on a page of a PDF document, or provides a way to interact with the user by means of the mouse and keyboard. PDF includes a wide variety of standard annotation types.
A watermark annotation (PDF 1.6) is used to represent graphics that are expected to be printed at a fixed size and position on a page, regardless of the dimensions of the printed page.
Annotation is the third type of PDF entities by which a watermark can be represented. Use the following code snippet to add watermark annotation to a PDF document using PdfAnnotationWatermarkOptions.
advanced_usage.add_watermarks_to_pdf.PdfAddAnnotationWatermark
PdfLoadOptionsloadOptions=newPdfLoadOptions();// Specify an absolute or relative path to your document. Ex: "C:\\Docs\\document.pdf"
Watermarkerwatermarker=newWatermarker("document.pdf",loadOptions);PdfAnnotationWatermarkOptionsoptions=newPdfAnnotationWatermarkOptions();// Add text watermark
TextWatermarktextWatermark=newTextWatermark("This is a annotation watermark",newFont("Arial",8));textWatermark.setHorizontalAlignment(HorizontalAlignment.Left);textWatermark.setVerticalAlignment(VerticalAlignment.Top);watermarker.add(textWatermark,options);// Add image watermark
ImageWatermarkimageWatermark=newImageWatermark("protect.jpg");imageWatermark.setHorizontalAlignment(HorizontalAlignment.Right);imageWatermark.setVerticalAlignment(VerticalAlignment.Top);watermarker.add(imageWatermark,options);watermarker.save("document.pdf");imageWatermark.close();watermarker.close();
Print-only annotations
You can also add print only annotation watermark to the document using setPrintOnly() method of PdfAnnotationWatermarkOptions. The following code demonstrates this approach.
PdfLoadOptionsloadOptions=newPdfLoadOptions();// Specify an absolute or relative path to your document. Ex: "C:\\Docs\\document.pdf"
Watermarkerwatermarker=newWatermarker("document.pdf",loadOptions);TextWatermarktextWatermark=newTextWatermark("This is a print only test watermark. It won't appear in view mode.",newFont("Arial",8));BooleanisPrintOnly=true;// Annotation will be printed, but not displayed in pdf viewing application
PdfAnnotationWatermarkOptionsoptions=newPdfAnnotationWatermarkOptions();options.setPageIndex(0);options.setPrintOnly(isPrintOnly);watermarker.add(textWatermark,options);watermarker.save("document.pdf");watermarker.close();
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.