Skip to content

Commit 0a79b3c

Browse files
DOC: Fix stamping example (#2358)
See https://patch-diff.githubusercontent.com/raw/py-pdf/pypdf/pull/1945 Co-authored-by: dmjohnsson23 <dmjohn235@gmail.com>
1 parent c43ca15 commit 0a79b3c

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

docs/user/add-watermark.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,23 @@ Else use `merge_transformed_page()` with `Transformation()` if you need to trans
2525

2626
```python
2727
from pathlib import Path
28-
from typing import Union, Literal, List
28+
from typing import List, Union
2929

30-
from pypdf import PdfWriter, PdfReader
30+
from pypdf import PdfReader, PdfWriter, Transformation
3131

3232

3333
def stamp(
34-
content_pdf: Path,
35-
stamp_pdf: Path,
36-
pdf_result: Path,
37-
page_indices: Union[Literal["ALL"], List[int]] = "ALL",
34+
content_pdf: Union[Path, str],
35+
stamp_pdf: Union[Path, str],
36+
pdf_result: Union[Path, str],
37+
page_indices: Union[None, List[int]] = None,
3838
):
3939
stamp_page = PdfReader(stamp_pdf).pages[0]
4040

4141
writer = PdfWriter()
4242
# page_indices can be a List(array) of page, tuples are for range definition
43-
writer.append(content, pages=None if page_indices == "ALL" else page_indices)
43+
reader = PdfReader(content_pdf)
44+
writer.append(reader, pages=page_indices)
4445

4546
for content_page in writer.pages:
4647
content_page.merge_transformed_page(
@@ -49,9 +50,14 @@ def stamp(
4950
)
5051

5152
writer.write(pdf_result)
53+
54+
55+
stamp("example.pdf", "stamp.pdf", "out.pdf")
5256
```
5357

54-
If you are experiencing wrongly rotated watermarks/stamps, try to use `transfer_rotation_to_content()` on the corresponding pages beforehand to fix the page boxes.
58+
If you are experiencing wrongly rotated watermarks/stamps, try to use
59+
`transfer_rotation_to_content()` on the corresponding pages beforehand
60+
to fix the page boxes.
5561

5662
Example of stamp:
5763
![stamp.png](stamp.png)

0 commit comments

Comments
 (0)