# PDF からパスワードを削除する

パスワード保護されたPDF を復号し、開く際にパスワードが不要になるようにします。

暗号化された PDF からパスワードを削除します。現在ファイルを開くために使用しているパスワードを指定すると、パスワードなしで開けるドキュメントが返されます。API はステートレスです。ドキュメントはリージョン内で処理され、保存されることはありません。

## エンドポイント

<Endpoint method="POST" path="/v1/remove_password" />

すべてのリージョンで利用できます。ルーティングとデータレジデンシーについては、[リージョンとデータレジデンシー](/docs/api/regions-and-data-residency)を参照してください。

| リージョン       | URL                                              |
| -------------- | ------------------------------------------------ |
| グローバル       | `https://api.pdfblocks.com/v1/remove_password`   |
| 日本            | `https://jp.api.pdfblocks.com/v1/remove_password` |
| 米国            | `https://us.api.pdfblocks.com/v1/remove_password` |
| HIPAA 米国      | `https://hipaa.api.pdfblocks.com/v1/remove_password` |
| 欧州連合         | `https://eu.api.pdfblocks.com/v1/remove_password` |
| 英国            | `https://uk.api.pdfblocks.com/v1/remove_password` |
| カナダ           | `https://ca.api.pdfblocks.com/v1/remove_password` |
| オーストラリア    | `https://au.api.pdfblocks.com/v1/remove_password` |
| インド           | `https://in.api.pdfblocks.com/v1/remove_password` |
| ブラジル         | `https://br.api.pdfblocks.com/v1/remove_password` |

## 認証

すべてのリクエストは、HTTPS 経由で `X-API-Key` ヘッダーにシークレット API キーを設定して認証してください。キーの作成と管理は[ダッシュボード](https://dashboard.pdfblocks.com)から行います。詳細は[認証](/docs/api/authentication)を参照してください。

## リクエスト

このエンドポイントは `multipart/form-data` 形式のリクエストボディを受け付けます。

<ParamField name="file" type="file" required>
  暗号化された入力 PDF ドキュメント。
</ParamField>

<ParamField name="password" type="string" required>
  現在ファイルを開くために使用しているパスワード。最大256文字。
</ParamField>

<Note>
  パスワードを削除するには、そのパスワードを知っている必要があります。現在ドキュメントを開くために使用しているパスワードを指定してください。復元やブルートフォースによる解除の手段はありません。
</Note>

## 例

暗号化された PDF からパスワードを削除する例。

<CodeGroup>

```bash title="cURL"
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
```

```python title="Python"
# 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)
```

```javascript title="Node.js"
// 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 title="PHP"
<?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);
}
```

```ruby title="Ruby"
# 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?
```

```go title="Go"
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)
}
```

```csharp title="C#"
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());
```

</CodeGroup>

## レスポンス

成功すると、復号された PDF を本文とする `200 OK` が返されます。

```http
HTTP/1.1 200 OK
Content-Type: application/pdf
Content-Length: 48213
```

出力ドキュメントは、開く際にパスワードが不要になります。ページと内容は変更されません。上記の例のように、レスポンスの本文はそのままファイルにストリーミングしてください。サーバー側には何も保存されません。

## エラー

リクエストが失敗した場合は、`application/problem+json` 形式のボディが返されます。このエンドポイントで最も多いのは `400` で、指定した `password` でファイルを開けない場合に返されます。`errors` オブジェクトに該当するフィールド名が示されます：

```json
{
  "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."]
  }
}
```

`X-API-Key` が指定されていないか無効な場合は `401` が返されます。すべてのステータスコードとレスポンスの完全な形式については、[エラー](/docs/api/errors)を参照してください。

## 関連アクション

<CardGroup cols={2}>

<Card title="パスワードを追加" href="/docs/api/add-password-to-pdf">
  パスワードで PDF を暗号化します。
</Card>

<Card title="制限を削除" href="/docs/api/remove-restrictions-from-pdf">
  権限フラグをリセットします。
</Card>

<Card title="制限を追加" href="/docs/api/add-restrictions-to-pdf">
  権限フラグを設定します。
</Card>

<Card title="署名を削除" href="/docs/api/remove-signatures-from-pdf">
  ドキュメントから署名を削除します。
</Card>

</CardGroup>
