How to Remove PDF Password with cURL

Learn how to remove a known PDF open password with cURL for authorized downstream processing and document workflows.
Share this page

This tutorial shows you how to remove PDF password with cURL through the Encrypt PDF API Tool. You'll see how the upload, headers, operation fields, and JSON response fit together in a command that can remove PDF password from a terminal or script.

Why Remove PDF Password with cURL?

An authorized workflow may receive protected PDFs together with their open passwords but still need unencrypted input for OCR, extraction, conversion, or archival processing. Decryption creates a new resource that later API calls can use.

For example, a secure intake service can decrypt a supplier document, extract approved data, and remove the temporary decrypted copy immediately afterward. This keeps credential use inside an automated process instead of requiring desktop intervention.

The current password must be known. The API does not discover, recover, or bypass an unknown password, and the generated unencrypted file should be handled according to the sensitivity of its contents.

cURL Code Example

# By default, we use the US-based API service. This is the primary endpoint for global use.
API_URL="https://api.pdfrest.com"

# For GDPR compliance and enhanced performance for European users, you can switch to the EU-based service by uncommenting the URL below.
# For more information visit https://pdfrest.com/pricing#how-do-eu-gdpr-api-calls-work
# API_URL="https://eu-api.pdfrest.com"

DECRYPTED_OUTPUT=$(curl -X POST "$API_URL/decrypted-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 "current_open_password=password")

echo $DECRYPTED_OUTPUT | jq -r '.'

# All files uploaded or generated are automatically deleted based on the
# File Retention Period as shown on https://pdfrest.com/pricing.
# For immediate deletion of files, particularly when sensitive data
# is involved, an explicit delete call can be made to the API.

# Optional deletion step — OFF by default.
# Deletes all files in the workflow, including outputs. Save all desired files before enabling this step.
# Enable by uncommenting the next line to delete sensitive files
# DELETE_SENSITIVE_FILES=true
if [ "$DELETE_SENSITIVE_FILES" = "true" ]; then
  DECRYPTED_ID=$(jq -r '.outputId' <<< $DECRYPTED_OUTPUT)
  INPUT_PDF_ID=$(jq -r '.inputId' <<< $DECRYPTED_OUTPUT)
  curl -X POST "$API_URL/delete" \
    -H "Accept: application/json" \
    -H "Content-Type: multipart/form-data" \
    -H "Api-Key: xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" \
    -F "ids=$INPUT_PDF_ID, $DECRYPTED_ID" | jq -r '.'
fi

Source for Remove PDF Password: View the cURL sample on GitHub.

Breaking Down the Code

Choose the pdfRest service region

# By default, we use the US-based API service. This is the primary endpoint for global use.
API_URL="https://api.pdfrest.com"

# For GDPR compliance and enhanced performance for European users, you can switch to the EU-based service by uncommenting the URL below.
# For more information visit https://pdfrest.com/pricing#how-do-eu-gdpr-api-calls-work
# API_URL="https://eu-api.pdfrest.com"

The Remove PDF Password example routes to the US service through the active URL, while the commented hostname provides the EU option. Keep every Remove PDF Password input and generated resource ID in the same region.

Build the authenticated multipart request

DECRYPTED_OUTPUT=$(curl -X POST "$API_URL/decrypted-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 "current_open_password=password")

echo $DECRYPTED_OUTPUT | jq -r '.'

# All files uploaded or generated are automatically deleted based on the
# File Retention Period as shown on https://pdfrest.com/pricing.
# For immediate deletion of files, particularly when sensitive data
# is involved, an explicit delete call can be made to the API.

# Optional deletion step — OFF by default.
# Deletes all files in the workflow, including outputs. Save all desired files before enabling this step.
# Enable by uncommenting the next line to delete sensitive files
# DELETE_SENSITIVE_FILES=true
if [ "$DELETE_SENSITIVE_FILES" = "true" ]; then
  DECRYPTED_ID=$(jq -r '.outputId' <<< $DECRYPTED_OUTPUT)
  INPUT_PDF_ID=$(jq -r '.inputId' <<< $DECRYPTED_OUTPUT)
  curl -X POST "$API_URL/delete" \
    -H "Accept: application/json" \
    -H "Content-Type: multipart/form-data" \
    -H "Api-Key: xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" \

This POST targets the endpoint used by Remove PDF Password. For the Remove PDF Password request, Accept asks for JSON, Content-Type identifies the multipart payload, and Api-Key authenticates the call.

Upload the input file data

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

The Remove PDF Password request reads the local source from the path after @ and sends its bytes in the multipart file field. For Remove PDF Password, cURL treats the path as an upload rather than ordinary form text.

Set the operation-specific fields

-F "output=example_out" \
  -F "current_open_password=password")

The current_open_password form field authorizes decryption. The sample captures the JSON response so it can display the result and optionally delete both input and output resources.

Handle the response and optional cleanup

echo $DECRYPTED_OUTPUT | jq -r '.'

# All files uploaded or generated are automatically deleted based on the
# File Retention Period as shown on https://pdfrest.com/pricing.
# For immediate deletion of files, particularly when sensitive data
# is involved, an explicit delete call can be made to the API.

# Optional deletion step — OFF by default.
# Deletes all files in the workflow, including outputs. Save all desired files before enabling this step.
# Enable by uncommenting the next line to delete sensitive files
# DELETE_SENSITIVE_FILES=true
if [ "$DELETE_SENSITIVE_FILES" = "true" ]; then
  DECRYPTED_ID=$(jq -r '.outputId' <<< $DECRYPTED_OUTPUT)
  INPUT_PDF_ID=$(jq -r '.inputId' <<< $DECRYPTED_OUTPUT)
  curl -X POST "$API_URL/delete" \
    -H "Accept: application/json" \
    -H "Content-Type: multipart/form-data" \
    -H "Api-Key: xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" \
    -F "ids=$INPUT_PDF_ID, $DECRYPTED_ID" | jq -r '.'
fi

The sample prints the response with jq and leaves immediate deletion disabled. Enabling the guarded block extracts the input and output IDs and sends them to Delete Files after required results have been saved.

Beyond the Tutorial

You have now seen how to submit an authorized PDF password with cURL and receive a separate decrypted PDF resource for the next processing step.

Do not place real passwords in source control, logs, command history, or URLs. Limit access to the decrypted output, save only what the workflow requires, and enable the deletion block when sensitive temporary files should be removed immediately.

Continue exploring the Remove PDF Password workflow in API Lab. For the complete Remove PDF Password request contract, accepted values, defaults, and limitations, consult the Encrypt PDF API Tool documentation.

Note: The Remove PDF Password example above uploads a file with multipart form data. For source content already stored in pdfRest, the Remove PDF Password JSON payload example shows the resource-ID request shape.

Generate a self-service API Key now!
Create your FREE API Key to start processing PDFs in seconds, only possible with pdfRest.