Package: pdfoutliner
pdfoutlinerCommand line tool for generatingpdftk-stylebookmark files in a user-friendly way, and (optionally) outputs a PDF file with the specified outline.Table of ContentspdfoutlinerTable of ContentsWhyInstallationSample UsageWith PDF I/O:Writing a pdftk bookmark file only:TOC FormatSpecifying structure by subheading numberingSpecifying structure by indentationKeeping PDF flatAdditional OptionsDependencyWhyInstead of requiring a TOC file like this, aspdftkdoesBookmarkBegin
BookmarkTitle: PDF Reference (Version 1.5)
BookmarkLevel: 1
BookmarkPageNumber: 1
BookmarkBegin
BookmarkTitle: Contents
BookmarkLevel: 2
BookmarkPageNumber: 3To create a PDF file with a structured/nested outline with the script, you only need a TOC file that looks like this:PDF Reference (Version 1.5) 1
  Contents 3or perhaps better, this:1 PDF Reference (Version 1.5) 1
1.1 Contents 3Installationpip3 install pdfoutlinerSample UsageWith PDF I/O:pdfoutliner TOC --inpdf in.pdf -s STARTwhereSTARTis the page in the PDF where p. 1 is supposed to start, andTOCis the path to a table of contents file.See sectionTOC Formatfor details on the syntax.Writing a pdftk bookmark file only:pdfoutliner TOCFor more options, see sectionAdditional Options, or usepdfoutliner -hTOC FormatThe default table of contents format is1 Heading 1
1.2 Subheading 3
1.2.3 Subsubheading 5Each line has a numbering (not necessarily numerical), a title, and a page number, separated by space characters.The script will infer that "1 Heading" is level 1, "1.1 Subheading" is level 2, and so on.Alternatively, you canspecify the structure by indentation, orkeep the PDF flat.Specifying structure by subheading numberingThis is the default option. As mentioned, the format is1 Heading 1
1.1 Subheading 3
1.1.1 Subsubheading 5And the script will infer the structure from the numbering.If your TOC file looks like1. Heading 1
1.1. Subheading 3
1.1.1. Subsubheading 5i.e., has a trailing dot after each numbering, you could specify the style of the heading with--style 1.2.Specifying structure by indentationYou could also specify the structure of the outline by indentation with-d --indentation, followed by an escaped regex for 1 unit of indentation.For example, suppose my TOC looks likeHeading 1
  Subheading 3
    Subsubheading 5where the unit of indentation is 2 spaces, then usepdfoutliner TOC -d \\s\\sAnd the script will infer the structure from the subheading indentations.Keeping PDF flatUse-k --keepflatand the script will ignore any numbering or indentations. The output PDF will have a flat, unstructured outline.Heading 1
Subheading 3
Subsubheading 5Additional Optionsusage: pdfoutliner [-h] [-o OUTMARKS] [-d INDENTATION] [-k]
                      [--style {1.2,1.2.}] [--outpdf OUTPDF] [--inpdf INPDF]
                      [-s START]
                      toc

optional arguments:
  -h, --help            show this help message and exit

bookmark I/O:
  toc                   path to TOC file
  -o OUTMARKS, --outmarks OUTMARKS
                        name for pdftk bookmarks file. default is original toc
                        name + "_outlined"

bookmark structure:
  if both -d and -k are specified, -d will take precedence over -k

  -d INDENTATION, --indentation INDENTATION
                        escaped regex for 1 unit of indentation
  -k, --keepflat       keep outline flat
  --style {1.2,1.2.}    heading style. with or without a trailing dot. default
                        "1.2", i.e., no trailing dot

PDF I/O:
  --outpdf OUTPDF       path to output PDF file. default is input pdf name +
                        "_outlined.pdf" in input PDF's directory
  --inpdf INPDF         path to input PDF file
  -s START, --start START
                        page in the pdf document where page 1 is. default 1Dependencypdftkon macOS 10.11+, use the buildhere(optional)Tabulafor extracting a usable TOC from PDF files (along with some additionalregex golfing)