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

Add page_label to JSON output #81

Merged
merged 4 commits into from
Aug 10, 2023
Merged
Changes from 2 commits
Commits
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
31 changes: 10 additions & 21 deletions pdfannots/printer/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,19 @@ def annot_to_dict(

result = {
"type": annot.subtype.name,
"page": annot.pos.page.pageno + 1,
"page_number": annot.pos.page.pageno + 1,
0xabu marked this conversation as resolved.
Show resolved Hide resolved
"page_label": annot.pos.page.label,
"start_xy": (annot.pos.x, annot.pos.y),
"prior_outline": getattr(doc.nearest_outline(annot.pos), 'title', None),
"text": annot.gettext(remove_hyphens),
"contents": annot.contents,
"author": annot.author,
"created": annot.created.strftime('%Y-%m-%dT%H:%M:%S') if annot.created else None,
"color": annot.color.ashex() if annot.color else None
}

outline = doc.nearest_outline(annot.pos)
if outline:
result["prior_outline"] = outline.title

if annot.text:
result['text'] = annot.gettext(remove_hyphens)

if annot.contents:
result['contents'] = annot.contents

if annot.author:
result['author'] = annot.author

if annot.created:
result['created'] = annot.created.strftime('%Y-%m-%dT%H:%M:%S')

if annot.color:
result['color'] = annot.color.ashex()

return result
# Remove keys with None values in nested dictionary and return
return {k: v for k, v in result.items() if v is not None}


class JsonPrinter(Printer):
Expand Down
Loading