A PDF watermark can be added in three different ways, each with its own trade-offs:
XObjects — added to the real page content. They are not removed by simple sanitization, which makes them the hardest to remove.
Artifacts — added as page artifacts. Use PdfArtifactWatermarkOptions.
Annotations — added as page annotations. Use PdfAnnotationWatermarkOptions; these can be made print-only so they appear when the document is printed but are hidden on screen.
Add artifact and annotation watermarks
The example below adds an artifact text watermark, an annotation text watermark, and a print-only annotation image watermark.
fromgroupdocs.watermarkimportWatermarkerfromgroupdocs.watermark.watermarksimportTextWatermark,ImageWatermark,Fontfromgroupdocs.watermark.commonimportHorizontalAlignment,VerticalAlignmentfromgroupdocs.watermark.options.pdfimport(PdfLoadOptions,PdfArtifactWatermarkOptions,PdfAnnotationWatermarkOptions,)defadd_pdf_watermarks():withWatermarker("./document.pdf",PdfLoadOptions())aswatermarker:# Add as an artifactartifact_text=TextWatermark("Artifact",Font("Arial",8.0))artifact_text.horizontal_alignment=HorizontalAlignment.RIGHTwatermarker.add(artifact_text,PdfArtifactWatermarkOptions())# Add as an annotationannotation_text=TextWatermark("Annotation",Font("Arial",8.0))annotation_text.horizontal_alignment=HorizontalAlignment.LEFTannotation_text.vertical_alignment=VerticalAlignment.TOPwatermarker.add(annotation_text,PdfAnnotationWatermarkOptions())# Add a print-only annotation (visible when printed, hidden on screen)withImageWatermark("./logo.png")asimage_watermark:image_watermark.horizontal_alignment=HorizontalAlignment.RIGHTimage_watermark.vertical_alignment=VerticalAlignment.TOPoptions=PdfAnnotationWatermarkOptions()options.print_only=Truewatermarker.add(image_watermark,options)watermarker.save("./output.pdf")if__name__=="__main__":add_pdf_watermarks()
document.pdf and logo.png are the sample files used in this example. Download document.pdf and logo.png.
To work with watermarks already present in a PDF — extracting, modifying, or removing existing XObjects, artifacts, and annotations — see Existing objects in PDF document.
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.
On this page
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.