Skip to content

Commit 27409ba

Browse files
DOC: Correct the example of adding highlight annotation (#2341)
Fix example for Add the Highlight: the `pypdf.annotations.Highlight` requires `rect` and `quad_points` as input parameters not `vertices`
1 parent fd0a482 commit 27409ba

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

docs/user/adding-pdf-annotations.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -317,16 +317,21 @@ you can use the {py:class}`Highlight <pypdf.annotations.Highlight>`:
317317
```python
318318
from pypdf import PdfReader, PdfWriter
319319
from pypdf.annotations import Highlight
320+
from pypdf.generic import ArrayObject, FloatObject
320321

321322
pdf_path = os.path.join(RESOURCE_ROOT, "crazyones.pdf")
322323
reader = PdfReader(pdf_path)
323324
page = reader.pages[0]
324325
writer = PdfWriter()
325326
writer.add_page(page)
326327

328+
rect = (50, 550, 200, 650)
329+
quad_points = [rect[0], rect[1], rect[2], rect[1], rect[0], rect[3], rect[2], rect[3]]
330+
327331
# Add the highlight
328332
annotation = Highlight(
329-
vertices=[(50, 550), (200, 650), (70, 750), (50, 700)],
333+
rect=rect,
334+
quad_points=ArrayObject([FloatObject(quad_point) for quad_point in quad_points]),
330335
)
331336
writer.add_annotation(page_number=0, annotation=annotation)
332337

0 commit comments

Comments
 (0)