From 2928e30236296dabaf5f55817dc9f4ce4fcd5949 Mon Sep 17 00:00:00 2001 From: Jialun Date: Wed, 13 Dec 2023 02:56:11 +0100 Subject: [PATCH 1/3] Update adding-pdf-annotations.md Fix example for Add the Highlight: the `pypdf.annotations.Highlight` requires `rect` and `quad_points` as input parameters not `vertices` --- docs/user/adding-pdf-annotations.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/user/adding-pdf-annotations.md b/docs/user/adding-pdf-annotations.md index 4b372fe3c..c6cf4f80e 100644 --- a/docs/user/adding-pdf-annotations.md +++ b/docs/user/adding-pdf-annotations.md @@ -317,6 +317,8 @@ you can use the {py:class}`Highlight `: ```python from pypdf import PdfReader, PdfWriter from pypdf.annotations import Highlight +from pypdf.generic import ArrayObject +from pypdf.generic._base import FloatObject pdf_path = os.path.join(RESOURCE_ROOT, "crazyones.pdf") reader = PdfReader(pdf_path) @@ -324,9 +326,14 @@ page = reader.pages[0] writer = PdfWriter() writer.add_page(page) +rect = (50, 550, 200, 650) +quad_points = [rect[0], rect[1], rect[2], rect[1], rect[0], rect[3], rect[2], rect[3]] + # Add the highlight annotation = Highlight( - vertices=[(50, 550), (200, 650), (70, 750), (50, 700)], + rect=rect + quad_points=ArrayObject([FloatObject(quad_point) for quad_point in quad_points]), + ) writer.add_annotation(page_number=0, annotation=annotation) From 77e56c00f1c056bf4a4ad86fffc839ea180a89db Mon Sep 17 00:00:00 2001 From: Jialun Date: Wed, 13 Dec 2023 08:55:31 +0100 Subject: [PATCH 2/3] Update adding-pdf-annotations.md Added missing comma --- docs/user/adding-pdf-annotations.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/user/adding-pdf-annotations.md b/docs/user/adding-pdf-annotations.md index c6cf4f80e..d52572437 100644 --- a/docs/user/adding-pdf-annotations.md +++ b/docs/user/adding-pdf-annotations.md @@ -331,9 +331,8 @@ quad_points = [rect[0], rect[1], rect[2], rect[1], rect[0], rect[3], rect[2], re # Add the highlight annotation = Highlight( - rect=rect + rect=rect, quad_points=ArrayObject([FloatObject(quad_point) for quad_point in quad_points]), - ) writer.add_annotation(page_number=0, annotation=annotation) From 287ca5a0ba79d80328672cd0b5dfacfc67380941 Mon Sep 17 00:00:00 2001 From: Jialun Date: Thu, 14 Dec 2023 18:48:03 +0100 Subject: [PATCH 3/3] Update adding-pdf-annotations.md --- docs/user/adding-pdf-annotations.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/user/adding-pdf-annotations.md b/docs/user/adding-pdf-annotations.md index d52572437..1bfcef470 100644 --- a/docs/user/adding-pdf-annotations.md +++ b/docs/user/adding-pdf-annotations.md @@ -317,8 +317,7 @@ you can use the {py:class}`Highlight `: ```python from pypdf import PdfReader, PdfWriter from pypdf.annotations import Highlight -from pypdf.generic import ArrayObject -from pypdf.generic._base import FloatObject +from pypdf.generic import ArrayObject, FloatObject pdf_path = os.path.join(RESOURCE_ROOT, "crazyones.pdf") reader = PdfReader(pdf_path)