Logo
Apdf tutorials September 2026 4 min read

How to Password-Protect PDFs in an Agent Workflow

The documents that need passwords — statements, payslips, contracts — are exactly the ones produced in batches at the end of some other workflow. Which is why protection gets skipped: it's one more desktop-tool detour between “files are ready” and “files are sent.”

With Apdf connected over MCP, encryption is just another step the agent runs in the same conversation that produced the files — and, because the agent can read PDFs too, it verifies the lock actually held before anything leaves.

What you'll build
A client statement locked, verified and — when the archive needs it back — unlocked, all conversationally: “Protect it before it goes out” → locked · probed · “encrypted”: true
MCP access needs Pro (14-day trial, no card)
1

Connect the agent to Apdf

claude mcp add --transport http apdf https://apdf.io/mcp/main

Same endpoint in Claude Desktop (Settings → Connectors), Cursor, or anything else that speaks MCP — one OAuth sign-in, scoped to your workspace.

2

Lock it — and prove the lock held

You
Protect this statement before it goes out — user password okafor-jun26, owner password from our batch config. Then double-check it's actually locked.
Claude
apdf · add-pdf-security, read-pdf-metadata
Locked with AES and verified: probing the protected file without the password returns encrypted: true and nothing else — no title, no page count, no content. Opening it now requires the user password; full permissions stay behind the owner password.

The add-pdf-security call returns the protected file:

{
    "file": "https://apdf-files.s3.eu-central-1.amazonaws.com/73a991466a61e112b0f61.pdf",
    "expiration": "2026-07-23T10:38:26.955862Z"
}

And the verification probe shows what an outsider sees — which is the point:

{
    "title": null,
    "creator": null,
    "producer": null,
    "created": null,
    "modified": null,
    "pages": 0,
    "encrypted": true,
    "page_size": null,
    "file_size": 8396,
    "pdf_version": null
}
Tip: Two passwords, two jobs: the user password is what the recipient types to open the file; the owner password gates permissions and is required for the protect call. Keep real master passwords in your secret manager and reference them — a chat transcript is not a vault.
3

Unlock when the archive needs it back

You
For our internal archive copy, remove the protection again — password okafor-jun26.
Claude
apdf · remove-pdf-security, read-pdf-metadata
Done — the archive copy opens freely again: 9 pages, A4, no encryption. The protected copy you sent the client is untouched.
{
    "title": null,
    "creator": "pdf-lib (https://github.com/Hopding/pdf-lib)",
    "producer": "pdf-lib (https://github.com/Hopding/pdf-lib)",
    "created": "Thu Jul 23 11:10:06 2026 CEST",
    "modified": "Thu Jul 23 11:10:06 2026 CEST",
    "pages": 9,
    "encrypted": false,
    "page_size": "595 x 842 pts (A4)",
    "file_size": 7355,
    "pdf_version": "1.7"
}
Heads up: Result files expire after 1 hour — download the protected copies or have the agent push them to your storage as the batch's final step.

Chain it with the other tools and the whole delivery pipeline is one conversation: split the batch into per-client files, protect each with its client's password, verify, ship.

Where to go from here

The same connection carries every PDF operation — and the engagement layer behind them.

After the API call

Your code made the PDF.
Then it went dark.

Opened, read, re-read, dropped on page 4 — you never see any of it. Share the PDFs you generate through Apdf recipient links, and every signal becomes something you can act on: ping Slack, update the CRM, let an agent follow up. Same account, same API token, one more call.

Your PDF, after sending Live
document:loaded CFO
page:read p4 · 38s
link:clicked pricing

API · Webhook · MCP