Skip to main content

Programmatically add an outline to a PDF.

Project description

pdf-add-outline

Add an outline to a PDF file. What it says on the tin.

Installation

Install through pip:

pip install pdf-add-outline

Usage

$ pdf-add-outline --help
usage: pdf-add-outline [-h] -o OUTPUT [-d] [--increment INCREMENT] <pdf_file> <toc_file>

Add an outline to a PDF.

positional arguments:
  <pdf_file>            Input PDF
  <toc_file>            JSON- or TXT-encoded ToC file (file type suffix required)

options:
  -h, --help            show this help message and exit
  -o OUTPUT, --output OUTPUT
                        Resultant filename (required)
  -d, --dry             Output the parsed OutlineItem structure; don't touch the PDF
  --increment INCREMENT
                        Increase all entries by <increment> amount

Example

$ pdf-add-outline tests/fixtures/Situated_Learning.pdf tests/fixtures/situated_learning.txt -o situated_with_outline.pdf

ToC File Formats

$ head tests/fixtures/situated_learning.json
[
    ["Series Foreword", 11, []],
    ["Foreword by William F. Hanks", 13, []],
    ["Acknowledgments", 25, []],
    ["1. Legitimate Peripheral Participation", 27, [
        ["From apprenticeship to situated learning", 32, []],
        ["From situated learning to legitimate peripheral participation", 34, []],
        ["An analytic perspective on learning", 37, []],
        ["With legitimate peripheral participation", 39, []],
        ["The organization of this monograph", 42, []]
$ head tests/fixtures/situated_learning.txt
Series Foreword, 11
Foreword by William F. Hanks, 13
Acknowledgments, 25
1. Legitimate Peripheral Participation, 27
    From apprenticeship to situated learning, 32
    From situated learning to legitimate peripheral participation, 34
    An analytic perspective on learning, 37
    With legitimate peripheral participation, 39
    The organization of this monograph, 42
2. Practice, Person, Social World, 45

Development

  1. Prerequisites: Clone the repository. Install Poetry.

  2. Run poetry install in the root of the directory.

  3. Run the tests.

    $ poetry run pytest tests
    collected 4 items
    
    tests/test_parsing.py ....        [100%]
    
    ========== 4 passed in 0.03s ===========
    
  4. Run mypy.

    $ poetry run mypy pdf_add_outline tests
    Success: no issues found in 4 source files
    
  5. Run black.

    $ poetry run black pdf_add_outline tests
    All done! ✨ 🍰 ✨
    4 files left unchanged.
    

Acknowledgements

The excellent PikePDF package, which wraps the QPDF library. Jean Lave and Etienne Wenger's Situated Learning for the example (and test) table of contents.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pdf_add_outline-0.1.1.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

pdf_add_outline-0.1.1-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file pdf_add_outline-0.1.1.tar.gz.

File metadata

  • Download URL: pdf_add_outline-0.1.1.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.10.9 Darwin/22.1.0

File hashes

Hashes for pdf_add_outline-0.1.1.tar.gz
Algorithm Hash digest
SHA256 72c7359dc3b176d3f45ab380cfb0e0ac26ded968326698378b9e4362f37357b2
MD5 3c4a8fd994436e176fc7ea91a7c16e2c
BLAKE2b-256 67d102af69e09707cb260762308ee3ff58ce680af014cd073ca89bd163fd724d

See more details on using hashes here.

File details

Details for the file pdf_add_outline-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pdf_add_outline-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.10.9 Darwin/22.1.0

File hashes

Hashes for pdf_add_outline-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 42ba53f60bf21afb2ee24551528be269f137b81a91a479f005d3cd253f5f9e78
MD5 e7e7cc0181a6ed1b4b209610a14d1512
BLAKE2b-256 66900624e9869c3012a7de277628d8df903d184cc576644cda3cea86cd1616ce

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page