How to Change PDF Password with cURL

Learn how to modify a PDF password with the pdfRest Encrypt PDF API Tool using cURL
Share this page

Why Use Encrypt PDF with cURL?

The pdfRest Encrypt PDF API Tool is a powerful resource for developers looking to secure their PDF documents. By using this API, you can add and change PDF passwords to restrict access, ensuring that only individuals with the correct password can view or modify the document. This tutorial will guide you through the process of sending an API call to Encrypt PDF using cURL, a command-line tool used for making network requests.

You might need to encrypt PDF documents to protect sensitive information such as financial reports, legal contracts, or personal data. Whether you’re sending a confidential document to a colleague or storing it in an insecure location, encryption helps prevent unauthorized access. By modifying a current password to a new passord, you can ensure only users with the new password will be able to open the file. For instance, a healthcare provider might change a PDF password on patient records before sharing them with a new insurance company.

Change PDF Password with cURL Code Example

curl -X POST "" \
  -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 "current_open_password=password" \
  -F "new_open_password=newpassword"

Reference to the provided code can be found at GitHub.

Breaking Down the Code

This cURL command is used to make a POST request to the Encrypt PDF endpoint. Let’s break down the components of the command:

-X POST ""

This specifies that you are making a POST request to the Encrypt PDF endpoint.

-H "Accept: application/json"

This header indicates that the server’s response should be in JSON format.

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

This header tells the server that the request body contains form data.

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

Replace the placeholder with your actual API key to authenticate the request.

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

The '-F' flag is used to specify each field to be sent. This field contains the file path to the PDF you want to encrypt.

-F "output=example_out"

This field sets the name of the output file that will be created.

-F "current_open_password=password"

This field is the current password of the PDF if it is already protected.

-F "new_open_password=newpassword"

This field is the new password you want to set for the PDF file.

Beyond the Tutorial

By following the steps above, you've learned how to change a PDF password using the pdfRest API and cURL. This provides an additional layer of security to your PDF files by requiring a new password to open them. You've also seen how to structure an API call with cURL and pass various parameters to customize the request.

You are now ready to explore and demo all of the pdfRest API Tools in the API Lab. For further information and a comprehensive guide to using the pdfRest API, refer to the API Reference Guide.

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