How to Encrypt PDF with cURL

Learn how to use Encrypt PDF API Tool by pdfRest with cURL to password-protect a PDF
Share this page

Why Use Encrypt PDF with cURL?

The pdfRest Encrypt PDF API Tool is a powerful feature that allows users to secure their PDF documents by adding password protection. This tutorial will guide you through the process of sending an API call to Encrypt PDF using cURL, which is a versatile command-line tool used for transferring data with URLs. By using cURL, you can easily integrate PDF encryption into your workflow or application, ensuring that sensitive information within your PDFs remains confidential.

There are numerous scenarios where encrypting a PDF document is essential. For instance, a financial institution might need to send confidential reports to clients, or a healthcare provider may need to protect patient records. By encrypting these documents, they ensure that only individuals with the correct password can access the sensitive information, thus complying with privacy regulations and safeguarding against unauthorized access.

Encrypt PDF with cURL Code Example

curl -X POST "https://api.pdfrest.com/encrypted-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 "output=example_out" \
  -F "new_open_password=password"

Reference to the provided code: pdf-rest-api-samples.

Breaking Down the Code

The cURL command provided is used to make an API request to the pdfRest Encrypt PDF endpoint. Let's break down the command:

-X POST

This specifies the HTTP method for the request, which is POST, indicating that you are sending data to create or update a resource.

"https://api.pdfrest.com/encrypted-pdf"

This is the URL of the API endpoint that performs the encryption of the PDF file.

-H "Accept: application/json"

This header tells the server that the client expects a response in JSON format.

-H "Content-Type: multipart/form-data"

This header indicates that the data being sent in the request is multipart form data, which is necessary for uploading files.

-H "Api-Key: xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

This header includes your unique API key for authentication with the pdfRest service.

-F "file=@/path/to/file"

This form field specifies the path to the PDF file you want to encrypt. The '@' symbol indicates that a file is being uploaded.

-F "output=example_out"

This form field sets the name of the output file that will be created once the PDF is encrypted.

-F "new_open_password=password"

This form field sets the password that will be required to open the encrypted PDF.

Beyond the Tutorial

By following the steps above, you have learned how to encrypt a PDF document using the pdfRest API and cURL. This allows you to add an extra layer of security to your PDFs by requiring a password to open them. You can now integrate this functionality into your own applications or automate the encryption process for batches of PDF documents.

To explore and demo all of the pdfRest API Tools, visit the API Lab. For more detailed information and additional parameters, refer to the API Reference Guide.

Note: This is an example of a multipart API call. For code samples using JSON payloads, visit pdf-rest-api-samples with JSON payloads.

Generate a self-service API Key now!

Create your FREE API Key to start processing PDFs in seconds, only possible with pdfRest.

Compare Plans
Contact Us