Watermark PDF

Adding watermarks to PDF files is a great way to protect your valuable content and ensure that your work is properly credited. Whether you want to watermark your PDF online, or create a custom watermark using Python, the process is simple and straightforward. In this blog post, we’ll explore how to add a watermark to PDF files, both with online tools and by using Python. Whether you want to insert a text watermark, or add an image watermark, this guide will show you how to add a watermark in PDF online and how to add a watermark to PDF for free.

Info: Aspose provides free online PowerPoint tools that allow you to add watermarks to presentations and remove watermarks from presentations.

Insert Watermark API

Aspose.PDF Cloud is our award-winning REST API providing the features to create, manipulate and render PDF files to various output formats. It also enables you to load EPUB, HTML, TeX, SVG, XML, etc files and save them in PDF format with fewer code lines. The most amazing part of this API is its platform-independent capabilities. Implement and utilize PDF processing capabilities on any platform including Desktop, Web, or Mobile. No need to install Adobe Acrobat or other applications to accomplish your requirements.

As our emphasis in this article is towards Python language, so we need to first install Aspose.PDF Cloud SDK for Python which is a wrapper around Aspose.PDF Cloud API. The SDK is available for download over PIP and GitHub repository. So please execute the following command on the terminal/command prompt to install the latest version of SDK on the system.

 pip install asposepdfcloud

MS Visual Studio

In case you need to directly add the reference in your Python project within Visual Studio IDE, please search asposepdfcloud as a package under the Python environment window.

Aspose.PDF Cloud Python

Image 1:- Aspose.PDF Cloud SDK for Python package.

After the installation, we need to obtain the client credentials from Aspose.Cloud dashboard. In case you do not have an account, you may subscribe using GitHub or Google account.

Client Credentials

Image 2:- Client credentials on Aspose.Cloud dashboard.

Add Watermark to PDF using Python

Please follow the instructions given below to add text watermark in PDF document using Python.

  1. Create an instance of ApiClient class while providing Client ID & Client Secret details as arguments
  2. Secondly, create an instance of PdfApi class which takes ApiClient object as an argument
  3. Thirdly, specify the names of input PDF file, name of resultant PDF and the page number where watermark is required to be added
  4. Now, create a Stamp object and specify the properties related to rotate angle, opacity, horizontal and vertical alignment, watermark value, font details, foreground and background color information
Text watermark preview

Image 3:- Text Watermark added in PDF.

Use cURL command to add Text Watermark

cURL is a command-line tool that allows you to transfer data from or to a server using various protocols, including HTTP. It also provide a convenient mechanism for accessing REST APIs through the command line terminal. Since Aspose.PDF Cloud is based on REST architecture, so it can easily be accessed using the cURL commands.

Now, the first step is to generate a JSON Web Token (JWT) based on your individual client credentials specified over Aspose.Cloud dashboard. Please execute the following command to generate the JWT token:

curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=88d1cda8-b12c-4a80-b1ad-c85ac483c5c5&client_secret=406b404b2df649611e508bbcfcd2a77f" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"

After that, please execute the following command to add a text watermark in the PDF file, where rotate angle of 45 degrees, horizontal alignment is Left and Vertical alignment is specified as Bottom.

curl -v -X POST "https://api.aspose.cloud/v3.0/pdf/awesomeTable.pdf/pages/1/stamps/text" \
-H  "accept: application/json" \
-H  "authorization: Bearer <JWT Token>" \
-H  "Content-Type: application/json" \
-d "[  {    \"Background\": true,    \"HorizontalAlignment\": \"1\",    \"Opacity\": 0.5,    \"Rotate\": \"1\",    \"RotateAngle\": 45.,    \"XIndent\": 100,    \"YIndent\": 100,    \"Zoom\": 1.5,    \"TextAlignment\": \"0\",    \"Value\": \"Confidential\",    \"TextState\": {      \"FontSize\": 20,      \"Font\": \"Arial\",      \"ForegroundColor\": {        \"A\": 0,        \"R\": 200,        \"G\": 0,        \"B\": 0      },      \"BackgroundColor\": {        \"A\": 10,        \"R\": 0,        \"G\": 0,        \"B\": 0      },      \"FontStyle\": \"2\"    },    \"VerticalAlignment\": \"1\",    \"BottomMargin\": 10,    \"LeftMargin\": 10,    \"TopMargin\": 10,    \"RightMargin\": 10  }]"

Use cURL command to add Image Watermark

Please execute the following cURL command to add image watermark to PDF document and save the output in cloud storage.

In case you need to save the output on local drive, please specify “-o” argument.

curl -v -X POST "https://api.aspose.cloud/v3.0/pdf/awesomeTable.pdf/pages/1/stamps/image" \
-H  "accept: application/json" \
-H  "authorization: Bearer <JWT Token>" \
-H  "Content-Type: application/json" \
-d "[  {    \"Links\": [      {        \"Type\": \"Image\",        \"Title\": \"Image stamp\"      }    ],    \"Background\": true,    \"HorizontalAlignment\": \"LEFT\",    \"Opacity\": 1.0,    \"Rotate\": \"None\",    \"RotateAngle\": 0,    \"XIndent\": 0,    \"YIndent\": 0,    \"Zoom\": 0.5,    \"FileName\": \"confidential.jpg\",    \"Width\": 400,    \"Height\": 200,    \"VerticalAlignment\": \"TOP\",    \"BottomMargin\": 0,    \"LeftMargin\": 10,    \"TopMargin\": 10,    \"RightMargin\": 0  }]"
Image watermark preview

Image 4:- Image watermark in PDF.

The sample files used in the above example can be downloaded from awesomeTable.pdf, Text-Watermark.pdf, and Image-Watermark.pdf.

Conclusion

In conclusion, adding watermarks to PDF files is a quick and effective way to protect your content and ensure that it is properly credited. Whether you prefer to use an online tool or a Python script, there are plenty of options available to help you watermark your PDFs with ease. By following the steps outlined in this blog post, you can easily add watermarks to PDF files and secure your valuable information. So why wait? Start watermarking your PDF files today and give yourself peace of mind knowing that your work is protected.

You also get a leverage to download the source code of Cloud SDK from GitHub. Furthermore, if you have any related query or you encounter any issue while using the API, please feel free to contact us via the free product support forum.

We recommend visiting the following articles to learn about: