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 1 commit
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
29 changes: 10 additions & 19 deletions pdfannots/printer/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,19 @@ def annot_to_dict(

result = {
"type": annot.subtype.name,
"page": annot.pos.page.pageno + 1,
"page_number" "number": annot.pos.page.pageno + 1,
"page_label": getattr(annot.pos.page, 'label', None),
0xabu marked this conversation as resolved.
Show resolved Hide resolved
"start_xy": (annot.pos.x, annot.pos.y),
"prior_outline": getattr(doc.nearest_outline(annot.pos), 'title', None),
"text": annot.gettext(remove_hyphens) if annot.text else None,
"contents": getattr(annot, 'contents', None),
0xabu marked this conversation as resolved.
Show resolved Hide resolved
"author": getattr(annot, 'author', None),
"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()
# Remove keys with None values in nested dictionary
result = {k: v for k, v in result.items() if v is not None}
0xabu marked this conversation as resolved.
Show resolved Hide resolved

return result

Expand Down
Loading