> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dockiln.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Adding protection to a PDF

> Encrypt a PDF with an opening password and configure print, copy and modification permissions.

## Encrypt a document

On the 1.1 build, request `processing.protection` for a PDF. The worker uses qpdf with AES-256 encryption. Set a distinct **user password** when recipients must enter a password to open the document. Keep the **owner password** private.

Run this example on your server with the API origin, workspace key and two passwords supplied by your secret manager. It prints the job ID.

```js theme={null}
const { DOCKILN_URL, DOCKILN_API_KEY, PDF_OWNER_PASSWORD, PDF_USER_PASSWORD } = process.env;
if (!PDF_OWNER_PASSWORD || !PDF_USER_PASSWORD || PDF_OWNER_PASSWORD === PDF_USER_PASSWORD) {
  throw new Error("Set distinct owner and user passwords");
}
const response = await fetch(new URL("/v1/documents", DOCKILN_URL), {
  method: "POST",
  headers: {
    Authorization: `Bearer ${DOCKILN_API_KEY}`,
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    html: "<h1>Private statement</h1>",
    format: "pdf",
    processing: { protection: {
      ownerPassword: PDF_OWNER_PASSWORD, userPassword: PDF_USER_PASSWORD,
      print: false, copy: false, modify: false
    } }
  })
});
if (response.status !== 202) throw new Error(`Submission failed (${response.status})`);
console.log((await response.json()).id);
```

## Check the recipient experience

Poll the job, download its file and open it in a new PDF reader session. Verify that the user password unlocks the statement. If you omit the user password, a reader can open the file without one. Print, copy and modification flags depend on the reader honoring them. Keep passwords out of logs and share the opening password separately from the document.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.