{"id":43601968,"url":"https://github.com/xianghuzhao/pdf-bookmark","last_synced_at":"2026-02-04T06:05:50.018Z","repository":{"id":54258789,"uuid":"211253029","full_name":"xianghuzhao/pdf-bookmark","owner":"xianghuzhao","description":"Import and export pdf bookmark","archived":false,"fork":false,"pushed_at":"2022-07-25T15:22:08.000Z","size":85,"stargazers_count":44,"open_issues_count":3,"forks_count":8,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-25T07:21:18.359Z","etag":null,"topics":["bmk","bookmark","bookmarker","pdf","pdf-bookmarker"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xianghuzhao.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-27T06:40:34.000Z","updated_at":"2025-03-02T00:21:57.000Z","dependencies_parsed_at":"2022-08-13T10:10:55.500Z","dependency_job_id":null,"html_url":"https://github.com/xianghuzhao/pdf-bookmark","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/xianghuzhao/pdf-bookmark","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xianghuzhao%2Fpdf-bookmark","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xianghuzhao%2Fpdf-bookmark/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xianghuzhao%2Fpdf-bookmark/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xianghuzhao%2Fpdf-bookmark/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xianghuzhao","download_url":"https://codeload.github.com/xianghuzhao/pdf-bookmark/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xianghuzhao%2Fpdf-bookmark/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29072515,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-04T03:31:03.593Z","status":"ssl_error","status_checked_at":"2026-02-04T03:29:50.742Z","response_time":62,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bmk","bookmark","bookmarker","pdf","pdf-bookmarker"],"created_at":"2026-02-04T06:05:48.087Z","updated_at":"2026-02-04T06:05:50.011Z","avatar_url":"https://github.com/xianghuzhao.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PDF-Bookmark\n\n[![PyPI](https://badge.fury.io/py/pdf-bookmark.svg)](https://pypi.org/project/pdf-bookmark/)\n\nPDF-Bookmark is a tool for importing and exporting pdf bookmark\nwith the `bmk` format.\n\n\n## Installation\n\n```shell\n$ pip install pdf-bookmark\n```\n\n`pdf-bookmark` utilizes\n[PDFtk](https://www.pdflabs.com/tools/pdftk-server/)\nand [Ghostscript](https://www.ghostscript.com/)\nto export and import pdf bookmarks.\nThey must be installed before running `pdf-bookmark`.\n\n\n### PDFtk\n\nPDFtk is used here to export bookmark from pdf file.\nThe java port [pdftk-java](https://gitlab.com/pdftk-java/pdftk)\nmay also be OK.\n\nOn Arch Linux, `pdftk-java` could be installed by:\n\n```shell\n$ sudo pacman -S pdftk java-commons-lang\n```\n\nVerify the installation:\n\n```shell\n$ pdftk --version\n```\n\n\n### Ghostscript\n\nGhostscript is used here to import bookmark to pdf file.\n\nOn Arch Linux, it could be installed by:\n\n```shell\n$ sudo pacman -S ghostscript\n```\n\nVerify the installation:\n\n```shell\n$ gs --version\n```\n\n\n## bmk format\n\nThe `bmk` format is used to describe the bookmark of a pdf file.\nIt will be used to import bookmark into a pdf file.\n\n`bmk` format is easy to write.\nIt looks quite like the content of a book.\nSo you can copy the content and modify from it.\n\nEach line represents a bookmark item. The title and the page number are\nseparated by at least 4 dots \"`.`\".\n\nThe level of a bookmark is specified by the indentation of spaces.\nThe default indentation is 2 spaces, and the number of spaces could be\nconfigured with inline command.\n\nThis is a simple example of a `bmk` file.\n\n```\n序................1\nChapter 1................4\nChapter 2................5\n  2.1 Section 1................6\n    2.1.1 SubSection 1................6\n    2.1.2 SubSection 2................8\n  2.2 Section 2................12\nChapter 3................20\nAppendix................36\n```\n\nImport the bookmark and create a new pdf file:\n\n```shell\n$ pdf-bookmark -p input.pdf -b bookmark.bmk -o new.pdf\n```\n\n\n### Export bmk format\n\nThe `bmk` format could also be exported from a pdf file with bookmark.\nYou may also modify the bookmark from the exported one.\n\n```shell\n$ pdf-bookmark -p input.pdf\n```\n\n\n### Inline command\n\nThere could also be inline commands in the file to do more controls\non the bookmark. These commands start with `!!!` and modify some\nproperties of bookmark. The new property will affect bookmarks after\nthe line until it is changed again.\n\nIt is normal that the main body of a pdf file does not start from the\nfirst page of pdf, and the page number is not always arabic.\n\n```\n!!! collapse_level = 2\n\n!!! num_style = Roman\nPreface................I\nContent................IV\n\n!!! new_index = 12\n!!! num_style = Arabic\nIntroduction................1\nChapter 1................4\nChapter 2................5\n  2.1 Section 1................6\n  2.2 Section 2................7\nChapter 3................10\nAppendix................11\n```\n\nWith these inline commands, you do not need to recalculate the index\nnumber for each page.\n\nHere are all supported inline commands:\n\n* `new_index`. Default: 1.\n   The following bookmark index will be recalculated from the\n   new index number (`new_index + page - 1`).\n* `num_start`. Default: 1.\n   Specify the number of first page if it does not start from 1\n   (`new_index + page - num_start`).\n* `num_style`. Default: `Arabic`.\n   The page number style. Could be `Arabic`, `Roman` and `Letters`.\n* `collapse_level`. Default: 0.\n   On which level the bookmarks are collapsed. 0 means expand all.\n* `level_indent`. Default: 2.\n   Number of indentation spaces for a new level.\n\n\n## pdf-bookmark command\n\nThe `pdf-bookmark` command is installed by `pip install pdf-bookmark`.\n\n```\nusage: pdf-bookmark [-h] [-f {bmk,none,pdftk,pdfmark,json}]\n                    [-l COLLAPSE_LEVEL] [-b BOOKMARK] [-p PDF] [-o OUTPUT_PDF]\n\nImport and export PDF bookmark\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -f {bmk,none,pdftk,pdfmark,json}, --format {bmk,none,pdftk,pdfmark,json}\n                        the output format of bookmark\n  -l COLLAPSE_LEVEL, --collapse-level COLLAPSE_LEVEL\n                        the min level to be collapsed, 0 to expand all\n  -b BOOKMARK, --bookmark BOOKMARK\n                        the bookmark file to be imported\n  -p PDF, --pdf PDF     the input PDF file\n  -o OUTPUT_PDF, --output-pdf OUTPUT_PDF\n                        the output PDF file\n```\n\n\n## Example\n\n### Import bookmark\n\nThis will import the `bmk` bookmark into a pdf file:\n\n```shell\n$ pdf-bookmark -p input.pdf -b bookmark.bmk -o new.pdf\n```\n\nIf you would like to have a quite output:\n\n```shell\n$ pdf-bookmark -p input.pdf -b bookmark.bmk -f none -o new.pdf\n```\n\n### Export bookmark\n\nThis will export the `bmk` bookmark to stdout from a pdf file:\n\n```shell\n$ pdf-bookmark -p input.pdf\n```\n\nThe output format could be changed to `pdfmark`, `json`:\n\n```shell\n$ pdf-bookmark -p input.pdf -f pdfmark\n$ pdf-bookmark -p input.pdf -f json\n```\n\n### Change the collapse level\n\nThis will only change the collapse level of the pdf.\n\n```shell\n$ pdf-bookmark -p input.pdf -l 2 -o new.pdf\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxianghuzhao%2Fpdf-bookmark","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxianghuzhao%2Fpdf-bookmark","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxianghuzhao%2Fpdf-bookmark/lists"}