Quitar las restricciones de un PDF
Borre todas las restricciones de permiso de un PDF y devuelva la posibilidad de copiar, imprimir y editar.
Quite todas las restricciones de permiso de un documento PDF y devuelva la posibilidad de copiar, imprimir y editar. La API es stateless: su documento se procesa en la región y nunca se almacena.
Esto borra los indicadores de permiso, es decir las restricciones de copia, impresión y edición, no la contraseña necesaria para abrir el archivo. Para quitar esa, use Quitar la contraseña. Para ver el ciclo completo, consulte Proteger documentos.
Endpoint
/v1/remove_restrictionsDisponible en todas las regiones. Consulte Regiones y residencia de datos para el enrutamiento y la residencia de datos.
| Región | URL |
|---|---|
| Global | https://api.pdfblocks.com/v1/remove_restrictions |
| Estados Unidos | https://us.api.pdfblocks.com/v1/remove_restrictions |
| HIPAA de EE. UU. | https://hipaa.api.pdfblocks.com/v1/remove_restrictions |
| Unión Europea | https://eu.api.pdfblocks.com/v1/remove_restrictions |
| Reino Unido | https://uk.api.pdfblocks.com/v1/remove_restrictions |
| Canadá | https://ca.api.pdfblocks.com/v1/remove_restrictions |
| Australia | https://au.api.pdfblocks.com/v1/remove_restrictions |
| Japón | https://jp.api.pdfblocks.com/v1/remove_restrictions |
| India | https://in.api.pdfblocks.com/v1/remove_restrictions |
| Brasil | https://br.api.pdfblocks.com/v1/remove_restrictions |
Autenticación
Autentique cada solicitud con su clave de API secreta en la cabecera
X-API-Key, por HTTPS. Cree y administre sus claves desde el
dashboard. Consulte
Autenticación para más detalles.
Solicitud
El endpoint acepta un cuerpo de solicitud multipart/form-data.
filefilerequiredEl documento PDF de entrada.
Ejemplos
Quite todas las restricciones de permiso de un PDF:
curl https://api.pdfblocks.com/v1/remove_restrictions \
-H 'X-API-Key: your_api_key' \
-F file=@input.pdf \
-o unrestricted.pdf# pip install requests
import requests
with open('input.pdf', 'rb') as file:
response = requests.post(
'https://api.pdfblocks.com/v1/remove_restrictions',
headers={'X-API-Key': 'your_api_key'},
files={'file': file},
)
response.raise_for_status()
with open('unrestricted.pdf', 'wb') as output:
output.write(response.content)// 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');
const response = await fetch('https://api.pdfblocks.com/v1/remove_restrictions', {
method: 'POST',
headers: { 'X-API-Key': 'your_api_key' },
body,
});
if (!response.ok) throw new Error(`Request failed: ${response.status}`);
await writeFile('unrestricted.pdf', Buffer.from(await response.arrayBuffer()));<?php
$ch = curl_init('https://api.pdfblocks.com/v1/remove_restrictions');
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'),
],
]);
$pdf = curl_exec($ch);
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) === 200) {
file_put_contents('unrestricted.pdf', $pdf);
}# gem install http
require 'http'
response = HTTP
.headers('X-API-Key' => 'your_api_key')
.post('https://api.pdfblocks.com/v1/remove_restrictions', form: {
file: HTTP::FormData::File.new('input.pdf'),
})
File.write('unrestricted.pdf', response.body) if response.status.success?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.Close()
req, _ := http.NewRequest("POST", "https://api.pdfblocks.com/v1/remove_restrictions", &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("unrestricted.pdf")
defer out.Close()
io.Copy(out, res.Body)
}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" },
};
var response = await client.PostAsync(
"https://api.pdfblocks.com/v1/remove_restrictions", form);
response.EnsureSuccessStatusCode();
await File.WriteAllBytesAsync(
"unrestricted.pdf", await response.Content.ReadAsByteArrayAsync());Respuesta
Si todo va bien, la respuesta es 200 OK con el PDF sin restricciones como
cuerpo:
HTTP/1.1 200 OK
Content-Type: application/pdf
Content-Length: 48213La salida es el mismo documento con sus indicadores de permiso borrados: sus páginas y su contenido no cambian. Escriba el cuerpo directamente en un archivo, como hacen los ejemplos anteriores; en nuestro lado no se almacena nada.
Errores
Las solicitudes fallidas devuelven un cuerpo application/problem+json. El
error más habitual en este endpoint es un 400, que se devuelve cuando file no
es un PDF legible: el objeto errors nombra cada campo:
{
"type": "https://www.pdfblocks.com/docs/api/v1/error/400",
"title": "One or more validation errors occurred.",
"status": 400,
"errors": {
"file": ["Could not parse the PDF document. The file may be invalid or corrupt."]
}
}Una X-API-Key ausente o no válida devuelve un 401. Consulte
Errores para ver todos los códigos de estado y la forma
completa de la respuesta.