Skip to content

Commit

Permalink
Add 024-annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinThoma committed Oct 8, 2023
1 parent 10ec731 commit c8f35c3
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 6 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/json_consistency.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@


class AnnotationCount(BaseModel):
Highlight: int | None
Ink: int | None
Link: int | None
Text: int | None
Widget: int | None

def items(self) -> list[tuple[str, int]]:
return [
("Highlight", self.Highlight if self.Highlight else 0),
("Link", self.Link if self.Link else 0),
("Ink", self.Ink if self.Ink else 0),
("Text", self.Text if self.Text else 0),
("Widget", self.Widget if self.Widget else 0),
]

Expand Down Expand Up @@ -135,7 +141,7 @@ def check_meta(entry: PdfEntry) -> None:
seen_subtypes = []
for subtype, exp_count in sorted(entry.annotations.items()):
seen_subtypes.append(subtype)
if exp_count == 0 and pdf_annotations.get(subtype, 0) == 0:
if exp_count == pdf_annotations.get(subtype, 0):
continue
print(
f" - {subtype}: {exp_count} vs {pdf_annotations.get(subtype, 0)}"
Expand Down
Binary file added 024-annotations/annotated_pdf.pdf
Binary file not shown.
33 changes: 33 additions & 0 deletions 024-annotations/create_annotated_pdf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from fpdf import FPDF # pip install fpdf2
from datetime import datetime

pdf = FPDF()
pdf.set_creation_date(datetime(1990, 4, 28, 0, 0, 0))
pdf.set_creator("created by Martin Thoma")
pdf.set_producer("produced by FPDF2")
pdf.set_title("Annotated PDF")

pdf.add_page()
pdf.set_font("Helvetica", size=24)

pdf.text(x=10, y=20, txt="Some text.")
pdf.text_annotation(
x=60,
y=20,
text="This is a text annotation.",
)

with pdf.highlight("Highlight comment"):
pdf.text(50, 50, "Line 1")
pdf.set_y(50)
pdf.multi_cell(w=30, txt="Line 2")
pdf.cell(w=60, txt="Not highlighted", border=1)


pdf.ink_annotation(
[(10, 120), (20, 110), (30, 120), (20, 130), (10, 120)],
title="Lucas",
contents="Hello world!",
)

pdf.output("annotated_pdf.pdf")
32 changes: 27 additions & 5 deletions files.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@
"pages": 1,
"images": 0,
"forms": 1,
"annotations": {"Widget": 3}
"annotations": {
"Widget": 3
}
},
{
"path": "011-google-doc-document/google-doc-document.pdf",
Expand All @@ -164,7 +166,9 @@
"pages": 1,
"images": 0,
"forms": 1,
"annotations": {"Widget": 9}
"annotations": {
"Widget": 9
}
},
{
"path": "013-reportlab-overlay/reportlab-overlay.pdf",
Expand All @@ -184,7 +188,9 @@
"pages": 4,
"images": 0,
"forms": 0,
"annotations": {"Link": 9}
"annotations": {
"Link": 9
}
},
{
"path": "015-arabic/habibi.pdf",
Expand Down Expand Up @@ -224,7 +230,9 @@
"pages": 1,
"images": 0,
"forms": 0,
"annotations": {"Link": 1}
"annotations": {
"Link": 1
}
},
{
"path": "017-unreadable-meta-data/unreadablemetadata.pdf",
Expand Down Expand Up @@ -295,6 +303,20 @@
"images": 1,
"forms": 0,
"annotations": {}
},
{
"path": "024-annotations/annotated_pdf.pdf",
"producer": "produced by FPDF2",
"creation_date": "1990-04-28T00:00:00",
"encrypted": false,
"pages": 1,
"images": 1,
"forms": 0,
"annotations": {
"Text": 1,
"Highlight": 1,
"Ink": 1
}
}
]
}
}

0 comments on commit c8f35c3

Please sign in to comment.