# Encrypt a PDF with a password

> AES-256, with the printing, modification and extraction permissions you choose. The owner password is required, because permissions without one can be removed by any PDF tool. Nobody, including this service, can recover a password you lose.

Source: https://tools.vukem.dev/docs/api/tools.pdf-protect/

## Authentication

Send your API key as `Authorization: Bearer <key>`. The `X-API-Key` header works too, and `Authorization` wins when both are present. The key needs the `pdf:security` ability.

## Request body

Content type `application/json`.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `file_id` | `string` | yes | The id of an upload of yours. min length 1 |
| `idempotency_key` | `string` | no | Repeat a submission safely. max length 128 |
| `options` | [`PDFProtectOptions`](/docs/api/schemas#pdfprotectoptions) | yes | The passwords and the permissions |

## Responses

### 201 Created

Content type `application/json`. Schema: [`ConversionView`](/docs/api/schemas#conversionview).

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `bytes_in` | `integer (int64)` | - | Size of the input in bytes |
| `bytes_out` | `integer (int64)` | - | Size of the result in bytes, 0 until it finishes |
| `created_at` | `string (date-time)` | - | When it was submitted |
| `error_message` | `string` | - | What to tell the user, empty unless it failed |
| `error_type` | `string` | - | A code from the error taxonomy, empty unless it failed |
| `expires_at` | `string (date-time)` | - | When the result stops being downloadable |
| `finished_at` | `string (date-time)` or `null` | - | When it ended, or null |
| `id` | `string` | - | The conversion id, used to poll it, stream it or cancel it |
| `note` | `string` | - | What the conversion did, in its own words. Empty when the file says it all |
| `phase` | `string` | - | What it is doing now, empty once it has ended |
| `progress` | `integer` | - | Percentage from 0 to 100 |
| `started_at` | `string (date-time)` or `null` | - | When a worker picked it up, or null |
| `status` | `string` | - | One of pending, running, finished, error, cancelled |
| `tool` | `string` | - | Which conversion produced it |

### 401 Unauthorized

Content type `application/problem+json`. Error (RFC 9457 problem details). Schema: [`Problem`](/docs/api/schemas#problem).

The error follows RFC 9457. See [Errors](/docs/api/overview#errors).

### 422 Unprocessable Content

Content type `application/problem+json`. Validation failed; errors maps each field to its messages and issues lists each problem with its code, key and params. Schema: [`Problem`](/docs/api/schemas#problem).

The error follows RFC 9457. See [Errors](/docs/api/overview#errors).

### Any other status

Content type `application/problem+json`. Error (RFC 9457 problem details). Schema: [`Problem`](/docs/api/schemas#problem).

The error follows RFC 9457. See [Errors](/docs/api/overview#errors).

```bash
curl -X POST "http://localhost:3000/api/v1/tools/pdf-protect" \
  -H "Authorization: Bearer $VUKEM_TOOLS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "file_id": "01JQ8Z5X0K7M3N9P2R4T6V8W0Y",
  "idempotency_key": "my-retry-key",
  "options": {
    "allow_extract": false,
    "modify": "none",
    "owner_password": "a-different-password-you-keep",
    "print": "low",
    "user_password": "the-password-readers-will-need"
  }
}'
```

```python
import os

import requests

response = requests.post(
    "http://localhost:3000/api/v1/tools/pdf-protect",
    headers={"Authorization": f"Bearer {os.environ['VUKEM_TOOLS_API_KEY']}"},
    json={
        "file_id": "01JQ8Z5X0K7M3N9P2R4T6V8W0Y",
        "idempotency_key": "my-retry-key",
        "options": {
            "allow_extract": False,
            "modify": "none",
            "owner_password": "a-different-password-you-keep",
            "print": "low",
            "user_password": "the-password-readers-will-need",
        },
    },
    timeout=30,
)
response.raise_for_status()
print(response.json())
```

```javascript
const response = await fetch("http://localhost:3000/api/v1/tools/pdf-protect", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.VUKEM_TOOLS_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "file_id": "01JQ8Z5X0K7M3N9P2R4T6V8W0Y",
    "idempotency_key": "my-retry-key",
    "options": {
      "allow_extract": false,
      "modify": "none",
      "owner_password": "a-different-password-you-keep",
      "print": "low",
      "user_password": "the-password-readers-will-need"
    }
  }),
});
if (!response.ok) throw new Error(`${response.status} ${await response.text()}`);
console.log(await response.json());
```

```go
package main

import (
	"fmt"
	"io"
	"net/http"
	"os"
	"strings"
)

func main() {
	body := strings.NewReader(`{
  "file_id": "01JQ8Z5X0K7M3N9P2R4T6V8W0Y",
  "idempotency_key": "my-retry-key",
  "options": {
    "allow_extract": false,
    "modify": "none",
    "owner_password": "a-different-password-you-keep",
    "print": "low",
    "user_password": "the-password-readers-will-need"
  }
}`)
	req, err := http.NewRequest("POST", "http://localhost:3000/api/v1/tools/pdf-protect", body)
	if err != nil {
		panic(err)
	}
	req.Header.Set("Authorization", "Bearer "+os.Getenv("VUKEM_TOOLS_API_KEY"))
	req.Header.Set("Content-Type", "application/json")

	res, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer res.Body.Close()

	out, err := io.ReadAll(res.Body)
	if err != nil {
		panic(err)
	}
	fmt.Println(res.Status, string(out))
}
```

```php
<?php

$ch = curl_init("http://localhost:3000/api/v1/tools/pdf-protect");
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        "Authorization: Bearer " . getenv("VUKEM_TOOLS_API_KEY"),
        "Content-Type: application/json",
    ],
    CURLOPT_POSTFIELDS => '{
  "file_id": "01JQ8Z5X0K7M3N9P2R4T6V8W0Y",
  "idempotency_key": "my-retry-key",
  "options": {
    "allow_extract": false,
    "modify": "none",
    "owner_password": "a-different-password-you-keep",
    "print": "low",
    "user_password": "the-password-readers-will-need"
  }
}',
]);

$response = curl_exec($ch);
if ($response === false) {
    throw new RuntimeException(curl_error($ch));
}
echo curl_getinfo($ch, CURLINFO_HTTP_CODE), " ", $response, PHP_EOL;
```

```java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Example {
    public static void main(String[] args) throws Exception {
        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("http://localhost:3000/api/v1/tools/pdf-protect"))
            .header("Authorization", "Bearer " + System.getenv("VUKEM_TOOLS_API_KEY"))
            .header("Content-Type", "application/json")
            .method("POST", HttpRequest.BodyPublishers.ofString("""
                {
                  "file_id": "01JQ8Z5X0K7M3N9P2R4T6V8W0Y",
                  "idempotency_key": "my-retry-key",
                  "options": {
                    "allow_extract": false,
                    "modify": "none",
                    "owner_password": "a-different-password-you-keep",
                    "print": "low",
                    "user_password": "the-password-readers-will-need"
                  }
                }
                """))
            .build();

        HttpResponse<String> response = HttpClient.newHttpClient()
            .send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.statusCode() + " " + response.body());
    }
}
```

```csharp
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;

using var client = new HttpClient();
using var request = new HttpRequestMessage(
    HttpMethod.Post, "http://localhost:3000/api/v1/tools/pdf-protect");
request.Headers.Authorization = new AuthenticationHeaderValue(
    "Bearer", Environment.GetEnvironmentVariable("VUKEM_TOOLS_API_KEY"));
request.Content = new StringContent("""
{
  "file_id": "01JQ8Z5X0K7M3N9P2R4T6V8W0Y",
  "idempotency_key": "my-retry-key",
  "options": {
    "allow_extract": false,
    "modify": "none",
    "owner_password": "a-different-password-you-keep",
    "print": "low",
    "user_password": "the-password-readers-will-need"
  }
}
""", Encoding.UTF8, "application/json");

using var response = await client.SendAsync(request);
Console.WriteLine($"{(int)response.StatusCode} {await response.Content.ReadAsStringAsync()}");
```

```ruby
require "net/http"
require "uri"

uri = URI("http://localhost:3000/api/v1/tools/pdf-protect")
request = Net::HTTP::Post.new(uri)
request["Authorization"] = "Bearer #{ENV.fetch('VUKEM_TOOLS_API_KEY')}"
request["Content-Type"] = "application/json"
request.body = '{
  "file_id": "01JQ8Z5X0K7M3N9P2R4T6V8W0Y",
  "idempotency_key": "my-retry-key",
  "options": {
    "allow_extract": false,
    "modify": "none",
    "owner_password": "a-different-password-you-keep",
    "print": "low",
    "user_password": "the-password-readers-will-need"
  }
}'

response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
  http.request(request)
end
puts "#{response.code} #{response.body}"
```

**Response examples**

```json
{
  "bytes_in": 18452,
  "bytes_out": 0,
  "created_at": "2026-02-03T10:00:00Z",
  "error_message": "",
  "error_type": "",
  "expires_at": "2026-02-03T11:00:02Z",
  "finished_at": null,
  "id": "01JQ8Z5X0K7M3N9P2R4T6V8W0Y",
  "phase": "tracing",
  "progress": 60,
  "started_at": "2026-02-03T10:00:02Z",
  "status": "running",
  "tool": "pixels-to-svg"
}
```

```json
{
  "detail": "This action requires authentication.",
  "instance": "/api/v1/me",
  "request_id": "01JQZ8R4T6WQ2N9K3V5Y7B0C1D",
  "status": 401,
  "title": "Unauthorized",
  "type": "about:blank"
}
```

```json
{
  "detail": "1 field(s) are invalid.",
  "errors": {
    "abilities": [
      "Unknown abilities: image:resize. Allowed: pixels:svg, ..."
    ]
  },
  "instance": "/api/v1/tokens",
  "request_id": "01JQZ8R4T6WQ2N9K3V5Y7B0C1D",
  "status": 422,
  "title": "Validation failed",
  "type": "about:blank"
}
```

The examples are built from the schemas, so every value is a placeholder of its type. The tables above hold the fields that carry the real values.
