---
title: "Password protect and encrypt PDF"
method: POST
path: "/security/pdf/lock"
tags: ["Security"]
---

# Password protect and encrypt PDF

`POST /security/pdf/lock`

## Request

- Base URL: `https://api.filegraph.ai` (the document declares no server; this is the origin it was published from)
- URL: `https://api.filegraph.ai/security/pdf/lock`
- Auth: API key in header `X-API-Key`

Add password protection and set permissions on a PDF document.

## Password Types

- **User Password** (document open password): Required to open and view the PDF
- **Owner Password** (permissions password): Required to change restrictions

Recipients don't need the owner password to open the document, only to modify permissions.

## Encryption Algorithms

| Algorithm | Security Level | Compatibility |
|-----------|---------------|---------------|
| `Standard40Bit` | Low | Acrobat 3+ |
| `Standard128Bit` | Medium | Acrobat 5+ |
| `Aes128Bit` | High | Acrobat 7+ |
| `Aes256Bit` | Highest | Acrobat 9+ (recommended) |

## Permissions

Control what users can do with the document:

| Permission | Description |
|------------|-------------|
| `print_document` | Allow printing |
| `print_faithful_copy` | Allow high-quality printing |
| `copy_contents` | Allow copy/paste of text and graphics |
| `modify_contents` | Allow editing document content |
| `modify_annotations` | Allow adding comments and form fields |
| `fill_form_fields` | Allow filling forms and signing |
| `extract_contents` | Allow text/graphic extraction |
| `assemble_document` | Allow page manipulation (insert, delete, rotate) |

## Example

```python
import httpx

response = httpx.post(
    "https://api.filegraph.ai/security/pdf/lock",
    headers={"X-API-Key": "your-api-key"},
    files={"file": open("document.pdf", "rb")},
    data={
        "user_password": "openme123",
        "owner_password": "admin456",
        "encryption_algorithm": "Aes256Bit",
        "print_document": "true",
        "copy_contents": "false"
    }
)
```

## Response `200`

Successful Response

- LockResponse: Response for PDF lock/protect operation.
  - `filename` string, required: Output filename
  - `content_type` string, required: MIME type of the file
  - `size_bytes` integer, required: File size in bytes
  - `content_base64` string, required: Base64-encoded file content
  - `encryption_algorithm` string, required: Encryption algorithm used
  - `has_user_password` boolean, required: Whether a user (open) password was set
  - `has_owner_password` boolean, required: Whether an owner (permissions) password was set
  - `permissions` string[], required: List of permissions enabled on the document

## Other responses

- `422`: Validation Error

---

[API](https://skmtc.dev/filegraph/apis/docconvert-api.md) · [All operations](https://skmtc.dev/filegraph/apis/docconvert-api/llms.txt) · [OpenAPI document](https://skmtc.dev/filegraph/apis/docconvert-api/revisions/436255c85bd4?raw)
