Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAINT: Cleanup of annotations #1745

Merged
merged 29 commits into from
Jul 29, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8b3ced1
MAINT: Cleanup of annotations
MartinThoma Mar 25, 2023
0d619e6
Merge branch 'main' into annotations
MartinThoma Mar 26, 2023
d26b44b
Merge branch 'main' into annotations
MartinThoma Mar 29, 2023
6dc5f24
Restructure
MartinThoma Mar 29, 2023
b5e09c3
/Text should be /FreeText in FreeText class
MartinThoma Mar 30, 2023
9b63511
Use kwargs and super
MartinThoma Mar 30, 2023
3273d5f
Default for title bar
MartinThoma Mar 30, 2023
72951e2
Fix title_bar attribute - thanks pubpub-zz!
MartinThoma Mar 30, 2023
3c10fa0
Make MarkupAnnotation abstract + add docstring
MartinThoma Mar 30, 2023
ccb49ca
Expose markup annotation
MartinThoma Mar 30, 2023
a8a85e1
Annotation module docstring
MartinThoma Mar 30, 2023
182735e
Adjust deprecation messages
MartinThoma Mar 31, 2023
a93c271
Move popup-annotation
MartinThoma Mar 31, 2023
c32a298
Add deprections
MartinThoma Mar 31, 2023
bad1ceb
Adjust tests
MartinThoma Mar 31, 2023
6fcd6a5
Make flags a property
MartinThoma Mar 31, 2023
56959dd
Export AnnotationDictionary
MartinThoma Mar 31, 2023
0087edc
Fix flags
MartinThoma Mar 31, 2023
deca45b
Fix tests
MartinThoma Apr 1, 2023
5291312
Merge branch 'main' into annotations
MartinThoma Apr 3, 2023
1f0d485
BUG: Fix x_max / y_max
MartinThoma Apr 8, 2023
e41e238
Merge branch 'main' into annotations
MartinThoma Jun 11, 2023
b14199b
Merge branch 'main' into annotations
MartinThoma Jun 25, 2023
59f724b
Merge branch 'main' into annotations
MartinThoma Jul 6, 2023
0df6da0
Apply suggestions from code review
MartinThoma Jul 9, 2023
92af890
Merge branch 'main' into annotations
MartinThoma Jul 17, 2023
98a3178
Merge branch 'main' into annotations
MartinThoma Jul 29, 2023
dd5aaa9
Update test
MartinThoma Jul 29, 2023
e7ccd15
Make title_bar default to None instead of empty string
MartinThoma Jul 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ You can contribute to `pypdf on GitHub <https://github.com/py-pdf/pypdf>`_.
modules/RectangleObject
modules/Field
modules/PageRange
modules/AnnotationBuilder
modules/annotations
modules/Fit
modules/PaperSize

Expand Down
7 changes: 0 additions & 7 deletions docs/modules/AnnotationBuilder.rst

This file was deleted.

7 changes: 7 additions & 0 deletions docs/modules/annotations.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
The annotations module
----------------------

.. automodule:: pypdf.annotations
:members:
:undoc-members:
:show-inheritance:
34 changes: 18 additions & 16 deletions docs/user/adding-pdf-annotations.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ If you want to add text in a box like this

![](free-text-annotation.png)

you can use the {py:class}`AnnotationBuilder <pypdf.generic.AnnotationBuilder>`:
you can use the {py:class}`FreeText <pypdf.annotations.FreeText>`:

```python
from pypdf import PdfReader, PdfWriter
from pypdf.generic import AnnotationBuilder
from pypdf.annotations import FreeText

# Fill the writer with the pages you want
pdf_path = os.path.join(RESOURCE_ROOT, "crazyones.pdf")
Expand All @@ -36,8 +36,8 @@ writer = PdfWriter()
writer.add_page(page)

# Create the annotation and add it
annotation = AnnotationBuilder.free_text(
"Hello World\nThis is the second line!",
annotation = FreeText(
text="Hello World\nThis is the second line!",
rect=(50, 550, 200, 650),
font="Arial",
bold=True,
Expand Down Expand Up @@ -66,7 +66,7 @@ If you want to add a line like this:

![](annotation-line.png)

you can use the {py:class}`AnnotationBuilder <pypdf.generic.AnnotationBuilder>`:
you can use {py:class}`Line <pypdf.annotations.Line>`:

```python
pdf_path = os.path.join(RESOURCE_ROOT, "crazyones.pdf")
Expand All @@ -76,7 +76,7 @@ writer = PdfWriter()
writer.add_page(page)

# Add the line
annotation = AnnotationBuilder.line(
annotation = Line(
text="Hello World\nLine2",
rect=(50, 550, 200, 650),
p1=(50, 550),
Expand All @@ -95,7 +95,7 @@ If you want to add a line like this:

![](annotation-polyline.png)

you can use the {py:class}`AnnotationBuilder <pypdf.generic.AnnotationBuilder>`:
you can use {py:class}`PolyLine <pypdf.annotations.PolyLine>`:

```python
pdf_path = os.path.join(RESOURCE_ROOT, "crazyones.pdf")
Expand All @@ -105,7 +105,7 @@ writer = PdfWriter()
writer.add_page(page)

# Add the polyline
annotation = AnnotationBuilder.polyline(
annotation = Polyline(
vertices=[(50, 550), (200, 650), (70, 750), (50, 700)],
)
writer.add_annotation(page_number=0, annotation=annotation)
Expand All @@ -121,7 +121,7 @@ If you want to add a rectangle like this:

![](annotation-square.png)

you can use the {py:class}`AnnotationBuilder <pypdf.generic.AnnotationBuilder>`:
you can use {py:class}`Rectangle <pypdf.annotations.Rectangle>`:

```python
pdf_path = os.path.join(RESOURCE_ROOT, "crazyones.pdf")
Expand All @@ -131,7 +131,7 @@ writer = PdfWriter()
writer.add_page(page)

# Add the rectangle
annotation = AnnotationBuilder.rectangle(
annotation = Rectangle(
rect=(50, 550, 200, 650),
)
writer.add_annotation(page_number=0, annotation=annotation)
Expand All @@ -152,6 +152,8 @@ If you want to add a circle like this:

![](annotation-circle.png)

you can use {py:class}`Ellipse <pypdf.annotations.Ellipse>`:

```python
pdf_path = os.path.join(RESOURCE_ROOT, "crazyones.pdf")
reader = PdfReader(pdf_path)
Expand All @@ -160,7 +162,7 @@ writer = PdfWriter()
writer.add_page(page)

# Add the rectangle
annotation = AnnotationBuilder.ellipse(
annotation = Ellipse(
rect=(50, 550, 200, 650),
)
writer.add_annotation(page_number=0, annotation=annotation)
Expand All @@ -176,7 +178,7 @@ If you want to add a polygon like this:

![](annotation-polygon.png)

you can use the {py:class}`AnnotationBuilder <pypdf.generic.AnnotationBuilder>`:
you can use {py:class}`Polygon <pypdf.annotations.Polygon>`:

```python
pdf_path = os.path.join(RESOURCE_ROOT, "crazyones.pdf")
Expand All @@ -186,7 +188,7 @@ writer = PdfWriter()
writer.add_page(page)

# Add the line
annotation = AnnotationBuilder.polygon(
annotation = Polygon(
vertices=[(50, 550), (200, 650), (70, 750), (50, 700)],
)
writer.add_annotation(page_number=0, annotation=annotation)
Expand Down Expand Up @@ -233,7 +235,7 @@ writer.write("annotated-pdf-popup.pdf")
## Link

If you want to add a link, you can use
the {py:class}`AnnotationBuilder <pypdf.generic.AnnotationBuilder>`:
{py:class}`Link <pypdf.annotations.Link>`:

```python
pdf_path = os.path.join(RESOURCE_ROOT, "crazyones.pdf")
Expand All @@ -243,7 +245,7 @@ writer = PdfWriter()
writer.add_page(page)

# Add the line
annotation = AnnotationBuilder.link(
annotation = Link(
rect=(50, 550, 200, 650),
url="https://martin-thoma.com/",
)
Expand All @@ -264,7 +266,7 @@ writer = PdfWriter()
writer.add_page(page)

# Add the line
annotation = AnnotationBuilder.link(
annotation = Link(
rect=(50, 550, 200, 650), target_page_index=3, fit="/FitH", fit_args=(123,)
)
writer.add_annotation(page_number=0, annotation=annotation)
Expand Down
Loading