# Bildwasserzeichen zu einem PDF hinzufügen

Bringen Sie ein PNG- oder JPEG-Bild auf die Seiten eines PDF auf, mit Kontrolle über Transparenz, Rand und die betroffenen Seiten.

Fügen Sie einem PDF-Dokument ein Bildwasserzeichen hinzu. Geben Sie ein PNG
oder JPEG an und steuern Sie dessen Transparenz und Rand. Standardmäßig wird
das Wasserzeichen auf jeder Seite aufgebracht: Verwenden Sie den Parameter
[`pages`](#seiten-auswählen), um eine Teilmenge anzusprechen. Die API ist
*stateless*: Ihr Dokument wird in der Region verarbeitet und niemals
gespeichert.

## Endpoint

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

In allen Regionen verfügbar. Hinweise zu Routing und Datenresidenz finden Sie
unter [Regionen und Datenresidenz](/docs/api/regions-and-data-residency).

| Region                 | URL                                                      |
| ---------------------- | -------------------------------------------------------- |
| Global                 | `https://api.pdfblocks.com/v1/add_image_watermark`       |
| USA                    | `https://us.api.pdfblocks.com/v1/add_image_watermark`    |
| HIPAA USA              | `https://hipaa.api.pdfblocks.com/v1/add_image_watermark` |
| Europäische Union      | `https://eu.api.pdfblocks.com/v1/add_image_watermark`    |
| Vereinigtes Königreich | `https://uk.api.pdfblocks.com/v1/add_image_watermark`    |
| Kanada                 | `https://ca.api.pdfblocks.com/v1/add_image_watermark`    |
| Australien             | `https://au.api.pdfblocks.com/v1/add_image_watermark`    |
| Japan                  | `https://jp.api.pdfblocks.com/v1/add_image_watermark`    |
| Indien                 | `https://in.api.pdfblocks.com/v1/add_image_watermark`    |
| Brasilien              | `https://br.api.pdfblocks.com/v1/add_image_watermark`    |

## Authentifizierung

Authentifizieren Sie jede Anfrage über HTTPS mit Ihrem geheimen API-Schlüssel
im Header `X-API-Key`. Schlüssel erstellen und verwalten Sie im
[Dashboard](https://dashboard.pdfblocks.com). Einzelheiten finden Sie unter
[Authentifizierung](/docs/api/authentication).

## Anfrage

Der Endpoint akzeptiert einen Anfragetext im Format `multipart/form-data`.

<ParamField name="file" type="file" required>
  Das PDF-Eingabedokument.
</ParamField>

<ParamField name="image" type="file" required>
  Das Wasserzeichenbild, das auf jede Seite aufgebracht wird. Muss ein PNG oder
  JPEG sein. Wie Sie es anhängen, steht unter [Mit Dateien
  arbeiten](/docs/api/working-with-files).
</ParamField>

<ParamField name="transparency" type="integer" default="50">
  Die Transparenzstufe, von `0` (vollständig deckend) bis `100` (vollständig
  transparent).
</ParamField>

<ParamField name="margin" type="decimal" default="1.0">
  Der Abstand in Zoll vom Seitenrand zum Wasserzeichen. `0` oder größer.
</ParamField>

<ParamField name="pages" type="string">
  Die Seiten, auf die das Wasserzeichen aufgebracht wird, geschrieben als
  [Seitenbereich](#seiten-auswählen) wie `1..3,5`. Wird der Parameter
  weggelassen, wird das Wasserzeichen auf jede Seite angewendet. Maximal 1.000
  Zeichen.
</ParamField>

### Seiten auswählen

Der Parameter `pages` nimmt eine durch Kommas getrennte Liste von Seitenzahlen
und Bereichen entgegen, beginnend bei 1. Er wird als **Menge** behandelt:
Reihenfolge und Duplikate werden ignoriert, und das Wasserzeichen wird immer in
der Reihenfolge des Dokuments aufgebracht.

| Muster         | Wählt aus                               |
| -------------- | --------------------------------------- |
| *(weglassen)*  | Jede Seite                              |
| `1`            | Nur die erste Seite                     |
| `1..3,5`       | Die Seiten 1, 2, 3 und 5                |
| `2..`          | Seite 2 bis zur letzten Seite           |
| `..-2`         | Von der ersten bis zur vorletzten Seite |
| `-1`           | Die letzte Seite                        |

Siehe [Seiten auswählen](/docs/api/selecting-pages) für die vollständige
Referenz.

## Beispiele

Bringen Sie ein Logo mit 60 % Transparenz auf jeder Seite auf:

<CodeGroup>

```bash title="cURL"
curl https://api.pdfblocks.com/v1/add_image_watermark \
  -H 'X-API-Key: your_api_key' \
  -F file=@input.pdf \
  -F image=@logo.png \
  -F transparency=60 \
  -o watermarked.pdf
```

```python title="Python"
# pip install requests
import requests

with open('input.pdf', 'rb') as file, open('logo.png', 'rb') as image:
    response = requests.post(
        'https://api.pdfblocks.com/v1/add_image_watermark',
        headers={'X-API-Key': 'your_api_key'},
        files={'file': file, 'image': image},
        data={'transparency': 60},
    )

response.raise_for_status()
with open('watermarked.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('image', new Blob([await readFile('logo.png')]), 'logo.png');
body.set('transparency', '60');

const response = await fetch('https://api.pdfblocks.com/v1/add_image_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()));
```

```php title="PHP"
<?php
$ch = curl_init('https://api.pdfblocks.com/v1/add_image_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'),
        'image' => new CURLFile('logo.png', 'image/png'),
        'transparency' => '60',
    ],
]);

$pdf = curl_exec($ch);
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) === 200) {
    file_put_contents('watermarked.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/add_image_watermark', form: {
    file: HTTP::FormData::File.new('input.pdf'),
    image: HTTP::FormData::File.new('logo.png'),
    transparency: '60',
  })

File.write('watermarked.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()
	filePart, _ := form.CreateFormFile("file", "input.pdf")
	io.Copy(filePart, file)

	image, _ := os.Open("logo.png")
	defer image.Close()
	imagePart, _ := form.CreateFormFile("image", "logo.png")
	io.Copy(imagePart, image)

	form.WriteField("transparency", "60")
	form.Close()

	req, _ := http.NewRequest("POST", "https://api.pdfblocks.com/v1/add_image_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)
}
```

```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 ByteArrayContent(File.ReadAllBytes("logo.png")), "image", "logo.png" },
    { new StringContent("60"), "transparency" },
};

var response = await client.PostAsync(
    "https://api.pdfblocks.com/v1/add_image_watermark", form);
response.EnsureSuccessStatusCode();
await File.WriteAllBytesAsync(
    "watermarked.pdf", await response.Content.ReadAsByteArrayAsync());
```

</CodeGroup>

## Antwort

Bei Erfolg ist die Antwort `200 OK`; der Antworttext ist das PDF mit dem
aufgebrachten Wasserzeichen:

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

Die Ausgabe behält Seitenzahl und Abmessungen der Eingabe bei: Nur das
Wasserzeichen kommt hinzu. Schreiben Sie den Antworttext direkt in eine Datei,
wie es die Beispiele oben tun; auf unserer Seite wird nichts gespeichert.

## Fehler

Fehlgeschlagene Anfragen geben einen Antworttext vom Typ
`application/problem+json` zurück. Der häufigste Fehler bei diesem Endpoint ist
ein `400`, der zurückgegeben wird, wenn ein Parameter ungültig ist oder `image`
kein unterstütztes Format hat. Das Objekt `errors` nennt jedes Feld:

```json
{
  "type": "https://www.pdfblocks.com/docs/api/v1/error/400",
  "title": "One or more validation errors occurred.",
  "status": 400,
  "errors": {
    "image": ["The image must be a PNG or JPEG file."]
  }
}
```

Ein fehlender oder ungültiger `X-API-Key` gibt einen `401` zurück. Alle
Statuscodes und die vollständige Form der Antwort finden Sie unter
[Fehler](/docs/api/errors).

## Rezepte

Häufige Varianten. Klappen Sie eine auf, um sie in allen Sprachen zu sehen.

<AccordionGroup>

<Accordion title="Ein dezentes Logo auf jeder Seite">

<CodeGroup>

```bash title="cURL"
curl https://api.pdfblocks.com/v1/add_image_watermark \
  -H 'X-API-Key: your_api_key' \
  -F file=@input.pdf \
  -F image=@logo.png \
  -F transparency=85 \
  -o faint.pdf
```

```python title="Python"
import requests

with open('input.pdf', 'rb') as file, open('logo.png', 'rb') as image:
    response = requests.post(
        'https://api.pdfblocks.com/v1/add_image_watermark',
        headers={'X-API-Key': 'your_api_key'},
        files={'file': file, 'image': image},
        data={'transparency': 85},
    )

response.raise_for_status()
with open('faint.pdf', 'wb') as output:
    output.write(response.content)
```

```javascript title="Node.js"
import { readFile, writeFile } from 'node:fs/promises';

const body = new FormData();
body.set('file', new Blob([await readFile('input.pdf')]), 'input.pdf');
body.set('image', new Blob([await readFile('logo.png')]), 'logo.png');
body.set('transparency', '85');

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

if (!response.ok) throw new Error(`Request failed: ${response.status}`);
await writeFile('faint.pdf', Buffer.from(await response.arrayBuffer()));
```

```php title="PHP"
<?php
$ch = curl_init('https://api.pdfblocks.com/v1/add_image_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'),
        'image' => new CURLFile('logo.png', 'image/png'),
        'transparency' => '85',
    ],
]);

$pdf = curl_exec($ch);
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) === 200) {
    file_put_contents('faint.pdf', $pdf);
}
```

```ruby title="Ruby"
require 'http'

response = HTTP
  .headers('X-API-Key' => 'your_api_key')
  .post('https://api.pdfblocks.com/v1/add_image_watermark', form: {
    file: HTTP::FormData::File.new('input.pdf'),
    image: HTTP::FormData::File.new('logo.png'),
    transparency: '85',
  })

File.write('faint.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()
	filePart, _ := form.CreateFormFile("file", "input.pdf")
	io.Copy(filePart, file)

	image, _ := os.Open("logo.png")
	defer image.Close()
	imagePart, _ := form.CreateFormFile("image", "logo.png")
	io.Copy(imagePart, image)

	form.WriteField("transparency", "85")
	form.Close()

	req, _ := http.NewRequest("POST", "https://api.pdfblocks.com/v1/add_image_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("faint.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 ByteArrayContent(File.ReadAllBytes("logo.png")), "image", "logo.png" },
    { new StringContent("85"), "transparency" },
};

var response = await client.PostAsync(
    "https://api.pdfblocks.com/v1/add_image_watermark", form);
response.EnsureSuccessStatusCode();
await File.WriteAllBytesAsync(
    "faint.pdf", await response.Content.ReadAsByteArrayAsync());
```

</CodeGroup>

</Accordion>

<Accordion title="Ein Logo nur auf dem Deckblatt">

<CodeGroup>

```bash title="cURL"
curl https://api.pdfblocks.com/v1/add_image_watermark \
  -H 'X-API-Key: your_api_key' \
  -F file=@input.pdf \
  -F image=@logo.png \
  -F pages='1' \
  -o cover-stamped.pdf
```

```python title="Python"
import requests

with open('input.pdf', 'rb') as file, open('logo.png', 'rb') as image:
    response = requests.post(
        'https://api.pdfblocks.com/v1/add_image_watermark',
        headers={'X-API-Key': 'your_api_key'},
        files={'file': file, 'image': image},
        data={'pages': '1'},
    )

response.raise_for_status()
with open('cover-stamped.pdf', 'wb') as output:
    output.write(response.content)
```

```javascript title="Node.js"
import { readFile, writeFile } from 'node:fs/promises';

const body = new FormData();
body.set('file', new Blob([await readFile('input.pdf')]), 'input.pdf');
body.set('image', new Blob([await readFile('logo.png')]), 'logo.png');
body.set('pages', '1');

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

if (!response.ok) throw new Error(`Request failed: ${response.status}`);
await writeFile('cover-stamped.pdf', Buffer.from(await response.arrayBuffer()));
```

```php title="PHP"
<?php
$ch = curl_init('https://api.pdfblocks.com/v1/add_image_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'),
        'image' => new CURLFile('logo.png', 'image/png'),
        'pages' => '1',
    ],
]);

$pdf = curl_exec($ch);
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) === 200) {
    file_put_contents('cover-stamped.pdf', $pdf);
}
```

```ruby title="Ruby"
require 'http'

response = HTTP
  .headers('X-API-Key' => 'your_api_key')
  .post('https://api.pdfblocks.com/v1/add_image_watermark', form: {
    file: HTTP::FormData::File.new('input.pdf'),
    image: HTTP::FormData::File.new('logo.png'),
    pages: '1',
  })

File.write('cover-stamped.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()
	filePart, _ := form.CreateFormFile("file", "input.pdf")
	io.Copy(filePart, file)

	image, _ := os.Open("logo.png")
	defer image.Close()
	imagePart, _ := form.CreateFormFile("image", "logo.png")
	io.Copy(imagePart, image)

	form.WriteField("pages", "1")
	form.Close()

	req, _ := http.NewRequest("POST", "https://api.pdfblocks.com/v1/add_image_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("cover-stamped.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 ByteArrayContent(File.ReadAllBytes("logo.png")), "image", "logo.png" },
    { new StringContent("1"), "pages" },
};

var response = await client.PostAsync(
    "https://api.pdfblocks.com/v1/add_image_watermark", form);
response.EnsureSuccessStatusCode();
await File.WriteAllBytesAsync(
    "cover-stamped.pdf", await response.Content.ReadAsByteArrayAsync());
```

</CodeGroup>

</Accordion>

</AccordionGroup>

## Verwandte Aktionen

<CardGroup cols={2}>

<Card title="Textwasserzeichen hinzufügen" href="/docs/api/add-text-watermark-to-pdf">
  Bringen Sie Text statt eines Bildes auf.
</Card>

<Card title="Passwort hinzufügen" href="/docs/api/add-password-to-pdf">
  Verschlüsseln Sie das Dokument mit dem aufgebrachten Wasserzeichen.
</Card>

<Card title="Dokumente zusammenführen" href="/docs/api/merge-pdf-documents">
  Kombinieren Sie Dateien, bevor Sie das Wasserzeichen aufbringen.
</Card>

<Card title="Seiten extrahieren" href="/docs/api/extract-pages-from-pdf">
  Holen Sie die Seiten mit dem aufgebrachten Wasserzeichen heraus.
</Card>

</CardGroup>
