Remove the password from a PDF
Decrypt a password-protected PDF so it no longer requires a password to open. Supply the password that opens the file and get back a document that opens freely.
Remove the password from an encrypted PDF. Supply the password that currently opens the file and get back a document that opens without one. The API is stateless: your document is processed in-region and never stored.
Endpoint
/v1/remove_passwordAvailable in every region. See Regions & data residency for routing and data residency.
| Region | URL |
|---|---|
| Global | https://api.pdfblocks.com/v1/remove_password |
| United States | https://us.api.pdfblocks.com/v1/remove_password |
| US HIPAA | https://hipaa.api.pdfblocks.com/v1/remove_password |
| European Union | https://eu.api.pdfblocks.com/v1/remove_password |
| United Kingdom | https://uk.api.pdfblocks.com/v1/remove_password |
| Canada | https://ca.api.pdfblocks.com/v1/remove_password |
| Australia | https://au.api.pdfblocks.com/v1/remove_password |
| Japan | https://jp.api.pdfblocks.com/v1/remove_password |
| India | https://in.api.pdfblocks.com/v1/remove_password |
| Brazil | https://br.api.pdfblocks.com/v1/remove_password |
Authentication
Authenticate every request with your secret API key in the X-API-Key header,
over HTTPS. Create and manage keys from the
dashboard. See
Authentication for details.
Request
The endpoint accepts a multipart/form-data request body.
filefilerequiredThe encrypted input PDF document.
passwordstringrequiredThe password that currently opens the file. Maximum 256 characters.
Removing the password requires knowing it: supply the password that currently opens the document. There is no recovery or brute-force path.
Examples
Remove the password from an encrypted PDF:
curl https://api.pdfblocks.com/v1/remove_password \
-H 'X-API-Key: your_api_key' \
-F file=@input.pdf \
-F password='0pen-Sesame' \
-o unlocked.pdf# pip install requests
import requests
with open('input.pdf', 'rb') as file:
response = requests.post(
'https://api.pdfblocks.com/v1/remove_password',
headers={'X-API-Key': 'your_api_key'},
files={'file': file},
data={'password': '0pen-Sesame'},
)
response.raise_for_status()
with open('unlocked.pdf', 'wb') as output:
output.write(response.content)// Node.js 18+
import { readFile, writeFile } from 'node:fs/promises';
const body = new FormData();
body.set('file', new Blob([await readFile('input.pdf')]), 'input.pdf');
body.set('password', '0pen-Sesame');
const response = await fetch('https://api.pdfblocks.com/v1/remove_password', {
method: 'POST',
headers: { 'X-API-Key': 'your_api_key' },
body,
});
if (!response.ok) throw new Error(`Request failed: ${response.status}`);
await writeFile('unlocked.pdf', Buffer.from(await response.arrayBuffer()));<?php
$ch = curl_init('https://api.pdfblocks.com/v1/remove_password');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['X-API-Key: your_api_key'],
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => [
'file' => new CURLFile('input.pdf', 'application/pdf'),
'password' => '0pen-Sesame',
],
]);
$pdf = curl_exec($ch);
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) === 200) {
file_put_contents('unlocked.pdf', $pdf);
}# gem install http
require 'http'
response = HTTP
.headers('X-API-Key' => 'your_api_key')
.post('https://api.pdfblocks.com/v1/remove_password', form: {
file: HTTP::FormData::File.new('input.pdf'),
password: '0pen-Sesame',
})
File.write('unlocked.pdf', response.body) if response.status.success?package main
import (
"bytes"
"io"
"mime/multipart"
"net/http"
"os"
)
func main() {
var buf bytes.Buffer
form := multipart.NewWriter(&buf)
file, _ := os.Open("input.pdf")
defer file.Close()
part, _ := form.CreateFormFile("file", "input.pdf")
io.Copy(part, file)
form.WriteField("password", "0pen-Sesame")
form.Close()
req, _ := http.NewRequest("POST", "https://api.pdfblocks.com/v1/remove_password", &buf)
req.Header.Set("Content-Type", form.FormDataContentType())
req.Header.Set("X-API-Key", "your_api_key")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
out, _ := os.Create("unlocked.pdf")
defer out.Close()
io.Copy(out, res.Body)
}using var client = new HttpClient();
client.DefaultRequestHeaders.Add("X-API-Key", "your_api_key");
using var form = new MultipartFormDataContent
{
{ new ByteArrayContent(File.ReadAllBytes("input.pdf")), "file", "input.pdf" },
{ new StringContent("0pen-Sesame"), "password" },
};
var response = await client.PostAsync(
"https://api.pdfblocks.com/v1/remove_password", form);
response.EnsureSuccessStatusCode();
await File.WriteAllBytesAsync(
"unlocked.pdf", await response.Content.ReadAsByteArrayAsync());Response
On success, the response is 200 OK with the decrypted PDF as the body:
HTTP/1.1 200 OK
Content-Type: application/pdf
Content-Length: 48213The output document no longer requires a password to open: its pages and content are unchanged. Stream the body straight to a file, as the examples above do; nothing is stored on our side.
Errors
Failed requests return an application/problem+json body. The most common one
for this endpoint is a 400, returned when the supplied password doesn’t open
the file. The errors object names each field:
{
"type": "https://www.pdfblocks.com/docs/api/v1/error/400",
"title": "One or more validation errors occurred.",
"status": 400,
"errors": {
"password": ["The password is incorrect."]
}
}A missing or invalid X-API-Key returns a 401. See
Errors for every status code and the full response shape.