Add Watermark via Python

Add watermarks to PDF document programmatically using Aspose.PDF for Python for .NET

Add Watermark to PDF File Using Python for .NET Tool

In order to add Watermark to PDF File, we’ll use Aspose.PDF for Python API, which is a feature-rich, powerful, and easy-to-use document manipulation API for .NET. Open NuGet package manager, search for Aspose.PDF and install. You may also use the following command from the Package Manager Console.

Python Package Manager Console

pip install aspose-pdf

Add Watermark via Python


To try the code in your environment, you need Aspose.PDF for Python.

  1. Load the PDF with an instance of Document.
  2. Create an instance of WatermarkArtifact.
  3. Set properties of WatermarkArtifact object.
  4. Add watermark using method Add of Aspose.Pdf.Page.Artifacts collection class.
  5. Save PDF file

Add Watermark to PDF - Python

import aspose.pdf as ap 

doc = ap.Document("1.pdf")

artifact = ap.WatermarkArtifact()
artifact.set_image("1.jpg")

artifact.artifact_horizontal_alignment = ap.HorizontalAlignment.CENTER
artifact.artifact_vertical_alignment = ap.VerticalAlignment.CENTER
artifact.rotation = 15
artifact.opacity = 1
artifact.is_background = True
doc.pages[1].artifacts.append(artifact)

#save result pdf to file
doc.save("add_watermark.pdf", ap.SaveFormat.PDF)