Skip to content

ENH: Add AnnotationBuilder.widget(...)#1207

Closed
MartinThoma wants to merge 1 commit intomainfrom
widget-annotation
Closed

ENH: Add AnnotationBuilder.widget(...)#1207
MartinThoma wants to merge 1 commit intomainfrom
widget-annotation

Conversation

@MartinThoma
Copy link
Copy Markdown
Member

@MartinThoma MartinThoma commented Aug 5, 2022

See #107

@MartinThoma
Copy link
Copy Markdown
Member Author

MartinThoma commented Aug 5, 2022

Looking at some examples:

>>> from PyPDF2 import PdfReader
>>> reader = PdfReader("pdf/04b33e0ac3e1dbfa2c575280319abf27.pdf")
>>> reader.pages[0].annotations
[IndirectObject(23, 0, 140234144846704), IndirectObject(25, 0, 140234144846704), IndirectObject(27, 0, 140234144846704), IndirectObject(29, 0, 140234144846704), IndirectObject(31, 0, 140234144846704), IndirectObject(33, 0, 140234144846704), IndirectObject(35, 0, 140234144846704), IndirectObject(37, 0, 140234144846704), IndirectObject(39, 0, 140234144846704), IndirectObject(41, 0, 140234144846704), IndirectObject(43, 0, 140234144846704), IndirectObject(45, 0, 140234144846704), IndirectObject(47, 0, 140234144846704), IndirectObject(49, 0, 140234144846704), IndirectObject(51, 0, 140234144846704), IndirectObject(53, 0, 140234144846704), IndirectObject(55, 0, 140234144846704), IndirectObject(57, 0, 140234144846704), IndirectObject(59, 0, 140234144846704), IndirectObject(61, 0, 140234144846704), IndirectObject(63, 0, 140234144846704), IndirectObject(65, 0, 140234144846704), IndirectObject(67, 0, 140234144846704), IndirectObject(69, 0, 140234144846704)]
>>> reader.pages[0].annotations[0]
IndirectObject(23, 0, 140234144846704)
>>> reader.pages[0].annotations[0].get_object()
{'/Rect': [191.775, 642.631, 504.437, 652.758], '/Subtype': '/Widget', '/BS': {'/S': '/S', '/W': 2}, '/Parent': IndirectObject(8, 0, 140234144846704), '/P': IndirectObject(21, 0, 140234144846704), '/Type': '/Annot', '/MK': {'/BG': [1, 1, 0]}, '/AP': {'/N': IndirectObject(24, 0, 140234144846704)}}
>>> reader.pages[0].annotations[0].get_object()['/Parent']
{'/T': 'Back', '/DA': '/Times 8 Tf 0 g', '/FT': '/Tx', '/Ff': 1, '/Kids': [IndirectObject(23, 0, 140234144846704), IndirectObject(25, 0, 140234144846704), IndirectObject(27, 0, 140234144846704), IndirectObject(29, 0, 140234144846704), IndirectObject(31, 0, 140234144846704), IndirectObject(33, 0, 140234144846704), IndirectObject(35, 0, 140234144846704), IndirectObject(37, 0, 140234144846704), IndirectObject(39, 0, 140234144846704), IndirectObject(41, 0, 140234144846704), IndirectObject(43, 0, 140234144846704), IndirectObject(45, 0, 140234144846704)]}
>>> reader.pages[0].annotations[1].get_object()
{'/Rect': [191.775, 630.606, 504.437, 640.732], '/Subtype': '/Widget', '/BS': {'/S': '/S', '/W': 2}, '/Parent': IndirectObject(8, 0, 140234144846704), '/P': IndirectObject(21, 0, 140234144846704), '/Type': '/Annot', '/MK': {'/BG': [1, 1, 0]}, '/AP': {'/N': IndirectObject(26, 0, 140234144846704)}}
>>> reader.pages[0].annotations[2].get_object()
{'/Rect': [91.1404, 607.82, 503.804, 617.947], '/Subtype': '/Widget', '/BS': {'/S': '/S', '/W': 2}, '/Parent': IndirectObject(8, 0, 140234144846704), '/P': IndirectObject(21, 0, 140234144846704), '/Type': '/Annot', '/MK': {'/BG': [1, 1, 0]}, '/AP': {'/N': IndirectObject(28, 0, 140234144846704)}}
>>> reader.pages[0].annotations[3].get_object()
{'/Rect': [192.407, 593.896, 505.07, 604.023], '/Subtype': '/Widget', '/BS': {'/S': '/S', '/W': 2}, '/Parent': IndirectObject(8, 0, 140234144846704), '/P': IndirectObject(21, 0, 140234144846704), '/Type': '/Annot', '/MK': {'/BG': [1, 1, 0]}, '/AP': {'/N': IndirectObject(30, 0, 140234144846704)}}

Beautifying the first:

{
    "/Type": "/Annot",
    "/Subtype": "/Widget",
    "/Rect": [
        191.775,
        642.631,
        504.437,
        652.758
    ],
    "/BS": {
        "/S": "/S",
        "/W": 2
    },
    "/Parent": "IndirectObject(...)",
    "/P": "IndirectObject(...)",
    "/MK": {
        "/BG": [
            1,
            1,
            0
        ]
    },
    "/AP": {
        "/N": "IndirectObject(...)"
    }
}

And looking at its indirect objects:

>>> reader.pages[0].annotations[0].get_object()['/P']
{'/CropBox': [0, 0, 612, 792], '/Annots': IndirectObject(22, 0, 140234144846704), '/Parent': IndirectObject(15, 0, 140234144846704), '/Contents': IndirectObject(75, 0, 140234144846704), '/Rotate': 0, '/MediaBox': [0, 0, 612, 792], '/Resources': IndirectObject(71, 0, 140234144846704), '/Type': '/Page'}

>>> reader.pages[0].annotations[0].get_object()['/Parent']
{'/T': 'Back', '/DA': '/Times 8 Tf 0 g', '/FT': '/Tx', '/Ff': 1, '/Kids': [IndirectObject(23, 0, 140234144846704), IndirectObject(25, 0, 140234144846704), IndirectObject(27, 0, 140234144846704), IndirectObject(29, 0, 140234144846704), IndirectObject(31, 0, 140234144846704), IndirectObject(33, 0, 140234144846704), IndirectObject(35, 0, 140234144846704), IndirectObject(37, 0, 140234144846704), IndirectObject(39, 0, 140234144846704), IndirectObject(41, 0, 140234144846704), IndirectObject(43, 0, 140234144846704), IndirectObject(45, 0, 140234144846704)]}

>>> reader.pages[0].annotations[0].get_object()['/AP']["/N"]
{'/Subtype': '/Form', '/Resources': {'/ProcSet': ['/PDF']}, '/BBox': [0, 0, 312.662, 10.1267]}

* build_appearence_characteristics
@codecov
Copy link
Copy Markdown

codecov bot commented Aug 6, 2022

Codecov Report

Merging #1207 (4e9d300) into main (759cbc3) will decrease coverage by 0.03%.
The diff coverage is 78.57%.

@@            Coverage Diff             @@
##             main    #1207      +/-   ##
==========================================
- Coverage   92.15%   92.12%   -0.04%     
==========================================
  Files          24       24              
  Lines        4948     4962      +14     
  Branches     1024     1029       +5     
==========================================
+ Hits         4560     4571      +11     
  Misses        244      244              
- Partials      144      147       +3     
Impacted Files Coverage Δ
PyPDF2/generic.py 91.43% <78.57%> (-0.18%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@MartinThoma MartinThoma added the help wanted We appreciate help everywhere - this one might be an easy start! label Aug 27, 2022
@MartinThoma
Copy link
Copy Markdown
Member Author

I'm closing this PR as I couldn't make it work

@MartinThoma MartinThoma closed this Jan 6, 2023
@stefan6419846 stefan6419846 deleted the widget-annotation branch February 25, 2024 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

help wanted We appreciate help everywhere - this one might be an easy start!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant