# Rimuovere la password da un PDF

Decrittografare un PDF protetto da password in modo che non richieda più una password per l’apertura.

Rimuovere la password da un PDF crittografato. Fornendo la password che apre
attualmente il file si ottiene un documento che si apre senza password. L’API è
*stateless*: il documento viene elaborato nella regione e non viene mai
memorizzato.

## Endpoint

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

Disponibile in tutte le regioni. Vedere [Regioni e residenza dei
dati](/docs/api/regions-and-data-residency) per il routing e la residenza dei
dati.

| Regione           | URL                                                  |
| ----------------- | ---------------------------------------------------- |
| Globale           | `https://api.pdfblocks.com/v1/remove_password`       |
| Stati Uniti       | `https://us.api.pdfblocks.com/v1/remove_password`    |
| HIPAA Stati Uniti | `https://hipaa.api.pdfblocks.com/v1/remove_password` |
| Unione europea    | `https://eu.api.pdfblocks.com/v1/remove_password`    |
| Regno Unito       | `https://uk.api.pdfblocks.com/v1/remove_password`    |
| Canada            | `https://ca.api.pdfblocks.com/v1/remove_password`    |
| Australia         | `https://au.api.pdfblocks.com/v1/remove_password`    |
| Giappone          | `https://jp.api.pdfblocks.com/v1/remove_password`    |
| India             | `https://in.api.pdfblocks.com/v1/remove_password`    |
| Brasile           | `https://br.api.pdfblocks.com/v1/remove_password`    |

## Autenticazione

Autenticare ogni richiesta con la chiave API segreta nell’intestazione
`X-API-Key`, su HTTPS. Le chiavi si creano e si gestiscono dalla
[dashboard](https://dashboard.pdfblocks.com). Vedere
[Autenticazione](/docs/api/authentication) per i dettagli.

## Richiesta

L’endpoint accetta un corpo della richiesta `multipart/form-data`.

<ParamField name="file" type="file" required>
  Il documento PDF crittografato di input.
</ParamField>

<ParamField name="password" type="string" required>
  La password che apre attualmente il file. Massimo 256 caratteri.
</ParamField>

<Note>
  Per rimuovere la password occorre conoscerla: fornire la password che apre
  attualmente il documento. Non esiste alcuna via di recupero né di forza bruta.
</Note>

## Esempi

Rimuovere la password da un PDF crittografato:

<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>

## Risposta

In caso di successo, la risposta è `200 OK` e il corpo contiene il PDF
decrittografato:

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

Il documento di output non richiede più una password per l’apertura: le pagine e
il contenuto sono invariati. Scrivere il corpo della risposta direttamente su un
file, come fanno gli esempi qui sopra: non viene memorizzato nulla dalla nostra
parte.

## Errori

Le richieste non riuscite restituiscono un corpo `application/problem+json`. Il
più comune per questo endpoint è un `400`, restituito quando la `password`
fornita non apre il file. L’oggetto `errors` nomina ogni campo:

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

Una `X-API-Key` mancante o non valida restituisce un `401`. Vedere
[Errori](/docs/api/errors) per tutti i codici di stato e la forma completa della
risposta.

## Azioni correlate

<CardGroup cols={2}>

<Card title="Aggiungere una password" href="/docs/api/add-password-to-pdf">
  Crittografare un PDF con una password.
</Card>

<Card title="Rimuovere le restrizioni" href="/docs/api/remove-restrictions-from-pdf">
  Azzerare i flag di autorizzazione.
</Card>

<Card title="Aggiungere restrizioni" href="/docs/api/add-restrictions-to-pdf">
  Impostare i flag di autorizzazione.
</Card>

<Card title="Rimuovere le firme" href="/docs/api/remove-signatures-from-pdf">
  Rimuovere le firme da un documento.
</Card>

</CardGroup>
