{"id":13844176,"url":"https://github.com/chroming/pdfdir","last_synced_at":"2025-05-15T15:04:38.784Z","repository":{"id":46146823,"uuid":"99800348","full_name":"chroming/pdfdir","owner":"chroming","description":"PDF导航（大纲/目录）添加工具","archived":false,"fork":false,"pushed_at":"2025-05-11T12:20:53.000Z","size":183,"stargazers_count":686,"open_issues_count":27,"forks_count":61,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-05-11T13:27:49.981Z","etag":null,"topics":["multi-platform","pdf","pyqt","pyqt5","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chroming.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-08-09T11:21:34.000Z","updated_at":"2025-05-11T12:20:56.000Z","dependencies_parsed_at":"2023-12-30T13:23:47.564Z","dependency_job_id":"db219e19-c348-46f7-9af7-f5cb7f82cb4f","html_url":"https://github.com/chroming/pdfdir","commit_stats":null,"previous_names":[],"tags_count":42,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chroming%2Fpdfdir","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chroming%2Fpdfdir/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chroming%2Fpdfdir/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chroming%2Fpdfdir/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chroming","download_url":"https://codeload.github.com/chroming/pdfdir/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254364270,"owners_count":22058878,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["multi-platform","pdf","pyqt","pyqt5","python"],"created_at":"2024-08-04T17:02:36.493Z","updated_at":"2025-05-15T15:04:38.746Z","avatar_url":"https://github.com/chroming.png","language":"Python","readme":"# pdfdir —— PDF导航书签添加工具\n\n[![Build Status](https://travis-ci.org/chroming/pdfdir.svg?branch=master)](https://travis-ci.org/chroming/pdfdir)\n\n根据已有的目录文本为你的PDF自动生成导航书签。\n\n![pdfdir](https://user-images.githubusercontent.com/9926275/29554882-5ea72db8-8753-11e7-9667-fe71e00b9c58.png)\n\n*此项目实现逻辑深受 https://github.com/ifnoelse/pdf-bookmark 项目影响。*\n\n## 软件功能\n\n根据网上或PDF中已有的目录内容自动将导航书签（大纲）插入PDF文件中。\n\n适用于以下场景：\n\n1. 扫描版电子书籍无导航书签；\n2. 文字版电子文档无导航书签但PDF中有目录。\n\n## 下载\n\nWindows/macOS/Ubuntu:\n\n[下载地址](https://github.com/chroming/pdfdir/releases)\n\n其他平台：\n\n请使用[源码方式](#通过源码运行)运行或自行打包。\n\n## 使用\n\n### 基本用法\n\n+ 选择文件：在 \"PDF文件路径\" 文本框中填入pdf文件路径（如D:/统计思维.pdf）或点击 \"打开\" 按钮通过文件管理器选择所需的pdf文件。\n+ 目录文本：将目录文本粘贴到“目录文本”框中。[如何获取目录文本](#获取目录文本)。\n+ 编辑写入目录（可选项）：根据目录文本自动生成的实际写入目录，可双击任一目录或页数进行编辑。同时支持拖动改变顺序/目录上下级关系。\n+ 编辑页数增加（可选项）：\n+ 写入：点击右下角的“写入”按钮，稍等片刻，待状态栏提示\"******* Finished!\"表示写入成功，此时可在pdf目录下找到包含书签的 *原文件名\\_new.pdf* 文件。\n\n###  获取目录文本\n\n目录文本是类似以下形式的文本内容：\n\n```\n中译版序言\n致中国读者\n作者来信\n前言\n第1章社会心理学导论2  \n第一编社会思维\n第2章社会中的自我32\n.....................\n结语605\n参考文献606\n```\n\n即：*标题+页数*形式。文本内容一般来源于网上书店（如亚马逊）或图书介绍网站（如豆瓣读书）。图书的介绍中一般会列出该书的目录文本，如亚马逊的在 *商品描述--目录* 下。注意：自动生成的目录完全依赖于目录文本，如果此文本有问题则生成的目录也会有问题。\n\n### 英文支持\n\n下载源码中的language/en.qm 放到程序同目录下 language/en.qm , 之后点击程序菜单栏中的 \"语言 -- English\" 即可切换为英文界面。\n\n### 已知问题\n\n+ 一般图书非正文部分（如序言，目录等）没有标页码或使用另一套页码标记，本程序将这些目录默认链接到第一页，如需修正这些链接可手动修改。\n+ 有些正文中的目录没有标页码，程序会将该条目录链接到上一个有页码的标题页。\n\n\n## 其他\n\n### 通过源码运行\n\n运行源码所需环境：\n\n+ Python2/3 均可，推荐Python3\n+ PyQt5\n+ PyPDF2\n+ six\n\n*注意：Python2与Python3 不兼容，某些系统（如macOS）系统自带Python2，使用`python`命令调用，若自行安装Python3则可能需要通过`python3`来调用Python3，pip同理。本文不区分python/python3, pip/pip3，请用户按当前系统所安装版本使用对应命令。*\n\n#### 获取代码\n\n`git clone https://github.com/chroming/pdfdir`\n\n#### 安装运行环境\n\n安装Python:\n\nhttps://www.python.org/downloads/\n\n安装依赖包:\n\n进入项目目录，执行：\n\n`pip install -r requirements.txt`\n\n`pip install -r pyqt5`\n\n若提示`No matching distribution found for pyqt5` 可参照[PyQt官方文档](http://pyqt.sourceforge.net/Docs/PyQt5/installation.html)进行安装。\n\n环境装好之后进入源码目录，运行以下命令：\n\n`python run_gui.py`\n\n如果不需要GUI界面:\n\n`python run.py`\n\n#### 通过源码运行命令行接口\n\n可以通过程序的`run_cli.py` 在没有Qt的环境下运行.  \n通过cli运行接口支持最多6级目录, 目录文本通过文件输入更加容易编辑.\n\n```\npython run_cli.py --help                                                                                                                                                                                                                            myrepo/pdfdir\nusage: run_cli.py [-h] [--offset OFFSET] [--l0 L0] [--l1 L1] [--l2 L2] [--l3 L3] [--l4 L4] [--l5 L5] pdfPath tocPath\n\nAdd content to PDF.\n\npositional arguments:\n  pdfPath          path of PDF\n  tocPath          path of contents file\n\noptions:\n  -h, --help       show this help message and exit\n  --offset OFFSET  Page offset of contents\n  --l0 L0          Regular expression of level 0 of content\n  --l1 L1          Regular expression of level 1 of content\n  --l2 L2          Regular expression of level 2 of content\n  --l3 L3          Regular expression of level 3 of content\n  --l4 L4          Regular expression of level 4 of content\n  --l5 L5          Regular expression of level 5 of content\n```\n\n### 打包源码\n\n如果你想在本机打包此程序：\n\n安装Pyinstaller\n\n`pip install pyinstaller`\n\n打包程序\n\n`pyinstaller.py -F run_gui.py -n \"PDFdir.exe\"  --noconsole`\n\n\n### 目录文本格式\n\n目前通过以下格式处理目录文本：\n\n*标题+页数+换行符*\n\n所有在一行的都被认为是一条目录。页数通过正则`(\\d*$)`匹配（匹配文本结尾处的所有数字），如果匹配不到则默认为第一页或上一条目录的页数。\n\n### 正则表达式简要说明\n\n正则表达式是编程中常用的一种工具。如果你没有使用过，可以把他当成类似于office中通配符的东西。\n本工具中可能会用到的正则：\n+ \\d 表示单个数字，如 \"第\\d章\" 可以匹配 \"第1章\", \"第2章\"……等，但不能匹配\"第10章\", 因为10是两个数字；\n+ \\w 表示单个字符，包括单个数字。如 \"第\\w章\" 可以匹配\"第1章\", \"第一章\"……等；\n+ . 表示任意字符，包括\\w所能匹配的所有字符以及空格等特殊字符；\n+ \\* 表示表达式中的前一个符号可以匹配不到，或匹配任意多次，如 \"第\\d*章\" 可以匹配 \"第章\", \"第1章\", \"第100章\"； \n+ \\+ 跟\\*类似，但是前一个符号不能匹配不到；\n+ {m, n} 匹配前一个字符m至n次。\n\n\n注意：\n\n+ \\*, \\+ 符号会匹配尽可能多的内容，比如如果用\"第\\w\\*章\" 来匹配，\"第一节如何阅读此章\"这段内容也会被匹配到，更好的写法是确定要匹配内容的长度，写成\"第\\w{1,2}章\"。\n+ 要匹配一个不是正则表达式中的正常字符直接写即可，如\"第\", \"1\", 甚至包括空格。但正则表达式中有定义用于匹配的一些特殊字符如果要作为普通字符匹配，则要在前面加一个\"\\\\\"，比如匹配\"1.1\"这种格式，可以写成\"\\d\\\\.\\d\"。\"\\\\\"符号本身也要如此。\n\n","funding_links":[],"categories":["Python","Python (1887)"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchroming%2Fpdfdir","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchroming%2Fpdfdir","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchroming%2Fpdfdir/lists"}