Package: pdf-bookmark
PDF-BookmarkPDF-Bookmark is a tool for importing and exporting pdf bookmark
with thebmkformat.Installation$pipinstallpdf-bookmarkpdf-bookmarkutilizesPDFtkandGhostscriptto export and import pdf bookmarks.
They must be installed before runningpdf-bookmark.PDFtkPDFtk is used here to export bookmark from pdf file.
The java portpdftk-javamay also be OK.On Arch Linux,pdftk-javacould be installed by:$sudopacman-Spdftkjava-commons-langVerify the installation:$pdftk--versionGhostscriptGhostscript is used here to import bookmark to pdf file.On Arch Linux, it could be installed by:$sudopacman-SghostscriptVerify the installation:$gs--versionbmk formatThebmkformat is used to describe the bookmark of a pdf file.
It will be used to import bookmark into a pdf file.bmkformat is easy to write.
It looks quite like the content of a book.
So you can copy the content and modify from it.Each line represents a bookmark item. The title and the page number are
separated by at least 4 dots ".".The level of a bookmark is specified by the indentation of spaces.
The default indentation is 2 spaces, and the number of spaces could be
configured with inline command.This is a simple example of abmkfile.序................1
Chapter 1................4
Chapter 2................5
  2.1 Section 1................6
    2.1.1 SubSection 1................6
    2.1.2 SubSection 2................8
  2.2 Section 2................12
Chapter 3................20
Appendix................36Import the bookmark and create a new pdf file:$pdf-bookmark-pinput.pdf-bbookmark.bmk-onew.pdfExport bmk formatThebmkformat could also be exported from a pdf file with bookmark.
You may also modify the bookmark from the exported one.$pdf-bookmark-pinput.pdfInline commandThere could also be inline commands in the file to do more controls
on the bookmark. These commands start with!!!and modify some
properties of bookmark. The new property will affect bookmarks after
the line until it is changed again.It is normal that the main body of a pdf file does not start from the
first page of pdf, and the page number is not always arabic.!!! collapse_level = 2

!!! num_style = Roman
Preface................I
Content................IV

!!! new_index = 12
!!! num_style = Arabic
Introduction................1
Chapter 1................4
Chapter 2................5
  2.1 Section 1................6
  2.2 Section 2................7
Chapter 3................10
Appendix................11With these inline commands, you do not need to recalculate the index
number for each page.Here are all supported inline commands:new_index. Default: 1.
The following bookmark index will be recalculated from the
new index number (new_index + page - 1).num_start. Default: 1.
Specify the number of first page if it does not start from 1
(new_index + page - num_start).num_style. Default:Arabic.
The page number style. Could beArabic,RomanandLetters.collapse_level. Default: 0.
On which level the bookmarks are collapsed. 0 means expand all.level_indent. Default: 2.
Number of indentation spaces for a new level.pdf-bookmark commandThepdf-bookmarkcommand is installed bypip install pdf-bookmark.usage: pdf-bookmark [-h] [-f {bmk,none,pdftk,pdfmark,json}]
                    [-l COLLAPSE_LEVEL] [-b BOOKMARK] [-p PDF] [-o OUTPUT_PDF]

Import and export PDF bookmark

optional arguments:
  -h, --help            show this help message and exit
  -f {bmk,none,pdftk,pdfmark,json}, --format {bmk,none,pdftk,pdfmark,json}
                        the output format of bookmark
  -l COLLAPSE_LEVEL, --collapse-level COLLAPSE_LEVEL
                        the min level to be collapsed, 0 to expand all
  -b BOOKMARK, --bookmark BOOKMARK
                        the bookmark file to be imported
  -p PDF, --pdf PDF     the input PDF file
  -o OUTPUT_PDF, --output-pdf OUTPUT_PDF
                        the output PDF fileExampleImport bookmarkThis will import thebmkbookmark into a pdf file:$pdf-bookmark-pinput.pdf-bbookmark.bmk-onew.pdfIf you would like to have a quite output:$pdf-bookmark-pinput.pdf-bbookmark.bmk-fnone-onew.pdfExport bookmarkThis will export thebmkbookmark to stdout from a pdf file:$pdf-bookmark-pinput.pdfThe output format could be changed topdfmark,json:$pdf-bookmark-pinput.pdf-fpdfmark
$pdf-bookmark-pinput.pdf-fjsonChange the collapse levelThis will only change the collapse level of the pdf.$pdf-bookmark-pinput.pdf-l2-onew.pdf