File: nametrees.rst

package info (click to toggle)
pikepdf 6.0.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 6,600 kB
  • sloc: python: 8,440; cpp: 4,645; makefile: 309; sh: 47
file content (34 lines) | stat: -rw-r--r-- 1,113 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
Name trees
**********

A name trees is a compound data structure in a PDFs, composed from primitive data
types, namely PDF dictionaries and arrays. pikepdf provides an interface that
significantly simplifies this complex data structure, making it as simple as
manipulating any Python dictionary.

In many cases, the |pdfrm| specifies that some information is stored in a name
tree. To access and manipulate those objects, use :class:`pikepdf.NameTree`.

Some objects that are stored in name trees include the objects in
``Pdf.Root.Names``:

* ``Dests``: named destinations
* ``URLS``: URLs
* ``JavaScript``: embedded PDF JavaScript
* ``Pages``: named pages
* ``IDS``: digital identifiers

Attached files (or embedded files) are managed in a name tree, but pikepdf
provides an interface specifically for managing them. Use that instead.

.. ipython::

    In [1]: from pikepdf import Pdf, Page, NameTree

    In [1]: pdf = Pdf.open('../tests/resources/outlines.pdf')

    In [1]: nt = NameTree(pdf.Root.Names.Dests)

    In [1]: print([k for k in nt.keys()])

    In [1]: nt['2'][0].objgen, nt['2'][1], nt['2'][2]