PDF Blocks
PreiseSupport
Kostenlos starten
Seite öffnen

Schnellstart

Eine erste authentifizierte Anfrage von Anfang bis Ende: einen Schlüssel holen, ein PDF senden, das zurückkommende Dokument speichern.

Der schnellste Weg von null zu einem verarbeiteten PDF: einen Schlüssel holen, einen Aufruf machen, das Ergebnis speichern. Kein SDK, keine Einrichtung außer einem API-Schlüssel und einem PDF auf der Festplatte.

Einen API-Schlüssel holen

Melden Sie sich beim Dashboard an und erstellen Sie einen API-Schlüssel. Kopieren Sie ihn an einen sicheren Ort: Sie senden ihn bei jeder Anfrage. Unter Authentifizierung steht, wie Schlüssel funktionieren und wie Sie sie sicher aufbewahren.

Einen Aufruf machen

Legen Sie ein PDF namens input.pdf in Ihr Arbeitsverzeichnis, ersetzen Sie your_api_key durch Ihren Schlüssel und führen Sie eines dieser Beispiele aus. Jedes bringt ein Wasserzeichen auf das Dokument auf und schreibt das Ergebnis nach watermarked.pdf.

cURLbash
curl https://api.pdfblocks.com/v1/add_text_watermark \
  -H 'X-API-Key: your_api_key' \
  -F file=@input.pdf \
  -F line_1='CONFIDENTIAL' \
  -o watermarked.pdf
Pythonpython
# pip install requests
import requests

with open('input.pdf', 'rb') as file:
    response = requests.post(
        'https://api.pdfblocks.com/v1/add_text_watermark',
        headers={'X-API-Key': 'your_api_key'},
        files={'file': file},
        data={'line_1': 'CONFIDENTIAL'},
    )

response.raise_for_status()
with open('watermarked.pdf', 'wb') as output:
    output.write(response.content)
Node.jsjavascript
// 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('line_1', 'CONFIDENTIAL');

const response = await fetch('https://api.pdfblocks.com/v1/add_text_watermark', {
  method: 'POST',
  headers: { 'X-API-Key': 'your_api_key' },
  body,
});

if (!response.ok) throw new Error(`Request failed: ${response.status}`);
await writeFile('watermarked.pdf', Buffer.from(await response.arrayBuffer()));
PHPphp
<?php
$ch = curl_init('https://api.pdfblocks.com/v1/add_text_watermark');
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'),
        'line_1' => 'CONFIDENTIAL',
    ],
]);

$pdf = curl_exec($ch);
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) === 200) {
    file_put_contents('watermarked.pdf', $pdf);
}
Rubyruby
# gem install http
require 'http'

response = HTTP
  .headers('X-API-Key' => 'your_api_key')
  .post('https://api.pdfblocks.com/v1/add_text_watermark', form: {
    file: HTTP::FormData::File.new('input.pdf'),
    line_1: 'CONFIDENTIAL',
  })

File.write('watermarked.pdf', response.body) if response.status.success?
Gogo
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("line_1", "CONFIDENTIAL")
	form.Close()

	req, _ := http.NewRequest("POST", "https://api.pdfblocks.com/v1/add_text_watermark", &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("watermarked.pdf")
	defer out.Close()
	io.Copy(out, res.Body)
}
C#csharp
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("CONFIDENTIAL"), "line_1" },
};

var response = await client.PostAsync(
    "https://api.pdfblocks.com/v1/add_text_watermark", form);
response.EnsureSuccessStatusCode();
await File.WriteAllBytesAsync(
    "watermarked.pdf", await response.Content.ReadAsByteArrayAsync());
Ihr PDF öffnen

Bei Erfolg antwortet die API mit 200 OK und dem Dokument mit Wasserzeichen als Antworttext:

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

Öffnen Sie watermarked.pdf: Es ist Ihre Eingabe, mit CONFIDENTIAL quer über jeder Seite. Das ist der ganze Vertrag: Ein PDF ging hinein, ein PDF kam heraus, und bei uns wurde nichts gespeichert.

Kein 200? Ein fehlender oder falscher Schlüssel liefert 401, ein unlesbares file liefert 400, beide als application/problem+json. Den vollständigen Katalog der Statuscodes finden Sie unter Fehler.

Nächste Schritte