Skip to content

ENH: Return Count information for outline item #1122

@mtd91429

Description

@mtd91429

Explanation

When retrieving outlines via PdfReader method _get_outlines(), the "/Count" attribute is ignored. The count is a required attribute for entries in an outline item dictionary with descendants. The count is the sum of the number of visible descendent outline items. If an outline is closed, the count is a negative number and the absolute value is the number of descendants that would be visible if the outline item were opened.

Code Example

An example of how this potentially could look once implemented:

from PyPDF2 import PdfReader
reader = PdfReader("example.pdf")

def show_tree(outlines, indent=0):
    for item in outlines:
        if isinstance(item, list):
            show_tree(item, indent+4)
        else:           
            print(f'{" "*indent}{item.title}, {item.count}')

show_tree(reader.outlines)
First, 6
    Second, None
    Third, None
    Fourth, 2
        Fifth, None
        Sixth, None
    Seventh, -2
        Eighth, None
        Ninth, None
Tenth, 4
    Eleventh, None
    Twelfth, None
    Thirteenth, None
    Fourteenth, None
Fifteenth, -2
    Sixteenth, None 
    Seventeenth, None 
Eighteenth, None
Nineteenth, 8
    Twentieth, None
    Twenty-first, None
    Twenty-second, None
    Twenty-third, None
    Twenty-fourth, None
    Twenty-fifth, None
    Twenty-sixth, None
    Twenty-seventh, None

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions