# Wasserzeichen auf bestimmten Seiten

Wie Sie ein Text- oder Bildwasserzeichen mit dem Selektor pages auf bestimmte Seiten begrenzen, und die häufigsten Muster.

Standardmäßig landet ein Wasserzeichen auf jeder Seite. Das Feld `pages` grenzt
das auf eine genaue Teilmenge ein (ein Deckblatt, einen Anhang, alles außer der
ersten Seite), sodass Sie es genau dort aufbringen, wo Sie es brauchen. Sowohl
[Textwasserzeichen hinzufügen](/docs/api/add-text-watermark-to-pdf) als auch
[Bildwasserzeichen hinzufügen](/docs/api/add-image-watermark-to-pdf) akzeptieren
es, und es funktioniert bei jeder Aktion, die ein Feld `pages` entgegennimmt,
auf dieselbe Weise.

## Der Selektor `pages`

`pages` ist eine durch Kommas getrennte Liste von Seitenzahlen und Bereichen,
beginnend bei 1. Sie wird als **Menge** behandelt: Reihenfolge und Duplikate
werden ignoriert, und das Wasserzeichen wird immer in der Reihenfolge des
Dokuments aufgebracht. Wird sie weggelassen, sind alle Seiten ausgewählt. Siehe
[Seiten auswählen](/docs/api/selecting-pages) für die vollständige Syntax.

| Ziel | Wert von `pages` |
| --- | --- |
| Nur das Deckblatt | `1` |
| Jede Seite außer der ersten | `2..` |
| Jede Seite außer der letzten | `..-2` |
| Nur die letzte Seite | `-1` |
| Ein Anhang ab Seite 8 | `8..` |
| Eine bestimmte Menge von Seiten | `1..3,5` |
| Die letzten drei Seiten | `-3..-1` |

## Wasserzeichen auf jeder Seite außer dem Deckblatt aufbringen

Eine häufige Anforderung: ein durchlaufender Vertraulichkeitshinweis auf dem
Hauptteil eines Dokuments, aber nicht über der Titelseite. Wählen Sie
`pages=2..`, also Seite 2 bis zur letzten Seite.

<CodeGroup>

```bash title="cURL"
curl https://api.pdfblocks.com/v1/add_text_watermark \
  -H 'X-API-Key: your_api_key' \
  -F file=@input.pdf \
  -F line_1='CONFIDENTIAL' \
  -F pages='2..' \
  -o watermarked.pdf
```

```python title="Python"
# 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', 'pages': '2..'},
    )

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('line_1', 'CONFIDENTIAL');
body.set('pages', '2..');

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()));
```

```php title="PHP"
<?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',
        'pages' => '2..',
    ],
]);

$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_text_watermark', form: {
    file: HTTP::FormData::File.new('input.pdf'),
    line_1: 'CONFIDENTIAL',
    pages: '2..',
  })

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()
	part, _ := form.CreateFormFile("file", "input.pdf")
	io.Copy(part, file)

	form.WriteField("line_1", "CONFIDENTIAL")
	form.WriteField("pages", "2..")
	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)
}
```

```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("CONFIDENTIAL"), "line_1" },
    { new StringContent("2.."), "pages" },
};

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());
```

</CodeGroup>

## Weitere Muster zur Zielauswahl

Das Einzige, was sich zwischen diesen Beispielen ändert, ist der Wert von
`pages`. Jedes Snippet schreibt in eine andere Ausgabedatei.

<CodeGroup>

```bash title="Nur das Deckblatt"
# pages=1: stamp just the title page.
curl https://api.pdfblocks.com/v1/add_text_watermark \
  -H 'X-API-Key: your_api_key' \
  -F file=@input.pdf \
  -F line_1='DRAFT' \
  -F pages='1' \
  -o cover.pdf
```

```bash title="Jede Seite außer der letzten"
# pages=..-2: the first page through the second-to-last.
curl https://api.pdfblocks.com/v1/add_text_watermark \
  -H 'X-API-Key: your_api_key' \
  -F file=@input.pdf \
  -F line_1='DO NOT DISTRIBUTE' \
  -F pages='..-2' \
  -o body.pdf
```

```bash title="Ab einem Anhang"
# pages=8..: page 8 to the end.
curl https://api.pdfblocks.com/v1/add_text_watermark \
  -H 'X-API-Key: your_api_key' \
  -F file=@input.pdf \
  -F line_1='APPENDIX' \
  -F pages='8..' \
  -o appendix.pdf
```

```bash title="Ausgewählte Seiten"
# pages=1..3,5: pages 1, 2, 3, and 5.
curl https://api.pdfblocks.com/v1/add_text_watermark \
  -H 'X-API-Key: your_api_key' \
  -F file=@input.pdf \
  -F line_1='REVIEW COPY' \
  -F pages='1..3,5' \
  -o review.pdf
```

</CodeGroup>

## Bildwasserzeichen lassen sich genauso ansteuern

Ein Bildwasserzeichen verwendet ein identisches Feld `pages`: Übergeben Sie ein
PNG oder JPEG im Feld `image` neben `file`. Damit wird ein Logo nur auf dem
Deckblatt aufgebracht:

<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 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={'pages': '1'},
    )

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('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('watermarked.pdf', Buffer.from(await response.arrayBuffer()));
```

</CodeGroup>

<Tip>
  Derselbe Selektor `pages` steuert auch die seitenorientierten Aktionen:
  [Seiten extrahieren](/docs/api/extract-pages-from-pdf), [Seiten
  entfernen](/docs/api/remove-pages-from-pdf) und [Seiten
  drehen](/docs/api/rotate-pages-in-pdf) lesen ihn alle auf dieselbe Weise.
  Einmal lernen, überall wiederverwenden.
</Tip>

## Siehe auch

<CardGroup cols={2}>

<Card title="Seiten auswählen" href="/docs/api/selecting-pages">
  Die vollständige Syntax für Seitenbereiche, einschließlich negativer Indizes.
</Card>

<Card title="Textwasserzeichen hinzufügen" href="/docs/api/add-text-watermark-to-pdf">
  Vorlagen, Farben, Deckkraft und Ränder.
</Card>

<Card title="Bildwasserzeichen hinzufügen" href="/docs/api/add-image-watermark-to-pdf">
  Bringen Sie ein PNG- oder JPEG-Logo statt Text auf.
</Card>

<Card title="Seiten extrahieren" href="/docs/api/extract-pages-from-pdf">
  Holen Sie mit demselben Selektor eine Teilmenge von Seiten heraus.
</Card>

</CardGroup>
