Skip to content

Utilize consistent internal nomenclature for outlines/bookmarks #1098

@mtd91429

Description

@mtd91429

Explanation

The PDF Reference uses the term "Outline" but recognizes "Bookmarks" as a synonymous term. From PDF Reference version 1.6 page 554 (section 8.2.2):

The outline consists of a tree-structured hierarchy of outline items (sometimes called bookmarks), which serve as a visual table of contents to display the document’s structure to the user.

There is inconsistency within PyPDF2 regarding the nomenclature. In the PdfReader object, these objects are referred to as outlines; however, within the PdfWriter object, they are referred to as both bookmarks (add_bookmark, add_bookmark_dict, add_bookmark_destination) and outlines (get_outline_root).

Most PDF reference software refers to these objects as "Bookmarks". For example, a screenshot from the Adobe Acrobat:

image

I propose that PyPDF2 be modified such that all user-facing aspects of the code have redundant and synonymous functions using both terms (outline and bookmark), but that all internal nomenclature adopts a single and consistent term which performs the manipulations. Specifically, I think internally it should be outline.

Proposed Code Example

from PyPDF2 import PdfReader, PdfWriter

reader = PdfReader("example.pdf")

reader.outlines
>>>[{'/Title': 'Bookmark 1', '/Page': IndirectObject(9, 0), '/Type': '/Fit'}, {'/Title': 'Bookmark 2', '/Page': IndirectObject(9, 0), '/Type': '/Fit', {'/Title': 'Bookmark 3', '/Page': IndirectObject(1, 0), '/Type': '/Fit'}]

reader.bookmarks
>>>[{'/Title': 'Bookmark 1', '/Page': IndirectObject(9, 0), '/Type': '/Fit'}, {'/Title': 'Bookmark 2', '/Page': IndirectObject(9, 0), '/Type': '/Fit', {'/Title': 'Bookmark 3', '/Page': IndirectObject(1, 0), '/Type': '/Fit'}]

writer = PdfWriter()
for page in reader.pages:
        writer.add_page(page)

writer.add_outline('Bookmark 4', 4)

writer.add_bookmark('Bookmark 5', 5)

Metadata

Metadata

Assignees

No one assigned

    Labels

    is-maintenanceAnything that is just internal: Simplifying code, syntax changes, updating docs, speed improvements

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions