How to Watermark PDF with cURL
Why Use Watermark PDF with cURL?
The pdfRest Watermark PDF API Tool is a powerful utility for adding watermarks to PDF documents programmatically. This tutorial will guide you through the process of making an API call to the Watermark PDF endpoint using cURL, a versatile command-line tool used for transferring data with URLs. By mastering this technique, you can automate the process of watermarking PDFs, which is essential for protecting intellectual property or branding documents without the need for manual intervention.
You might need to use the Watermark PDF API to batch process a collection of PDF documents by adding a company logo or confidential stamp before distributing them to clients or team members. This ensures that the documents are properly marked for their intended use or audience, which is particularly useful for legal documents, marketing materials, or any sensitive information that requires clear labeling.
Watermark PDF with cURL Code Example
curl -X POST "https://api.pdfrest.com/watermarked-pdf" \ -H "Accept: application/json" \ -H "Content-Type: multipart/form-data" \ -H "Api-Key: xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" \ -F "file=@/path/to/file" \ -F "watermark_text=watermark" \ -F "output=example_out"
Refer to the original code at GitHub.
Breaking Down the Code
This code snippet makes a POST request to the Watermark PDF endpoint:
curl -X POST "https://api.pdfrest.com/watermarked-pdf"
The -X POST
flag specifies that cURL should use the POST method, which is required to send data to the server.
Headers are set to accept JSON responses and to indicate the content type:
-H "Accept: application/json" \ -H "Content-Type: multipart/form-data"
The API key is sent as a header for authentication:
-H "Api-Key: xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
Replace xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
with your actual API key.
The file to be watermarked is included using the -F
flag, which denotes form data:
-F "file=@/path/to/file"
Replace /path/to/file
with the path to your PDF file.
The watermark text is specified with another -F
flag:
-F "watermark_text=watermark"
This will add the text "watermark" to the PDF. Change watermark
to your desired text.
Lastly, the output parameter is used to specify the name of the resulting watermarked PDF:
-F "output=example_out"
The resulting file will be named example_out.pdf
.
Beyond the Tutorial
By following this tutorial, you've learned how to use cURL to make a multipart API call to the pdfRest Watermark PDF endpoint. This skill enables you to automate the process of adding watermarks to PDF documents, which can be a significant time-saver in many business workflows. To further explore and demo all of the pdfRest API Tools, visit the API Lab. For more detailed information on the API, refer to the API Reference Guide.
Note: This is an example of a multipart API call. Code samples using JSON payloads can be found at GitHub.