pdf - 如何在Python中读取pdf中的书签?

标签 pdf python-2.7 pypdf

我一直在搜索高低,pyPdf,pyPdf2,pdfminer之类的东西,我想要的只是阅读pdf的书签及其相关页面,这样如果书签“第1章”在第5页上,我写 print(bookmarks) 它将打印“第 1, 5 章”或朝那个方向,有什么想法吗?谢谢!

最佳答案

您可以使用cpdf命令行工具,然后解析结果:

cpdf -list-bookmarks file.pdf

会产生类似的东西

0 "Purpose" 1 
0 "To help students visually organize similarities and differences between three ideas, objects, or sets." 1 
0 "To increase awareness of relationships between ideas, objects, or sets" 2 open
1 "Teacher Instructions" 3

其中的列是树中的级别、书签文本、它指向的页码。

关于pdf - 如何在Python中读取pdf中的书签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20825776/

相关文章:

java - iText PDF - 如何添加多行页脚?

java - 非官方 iText 4.2.1 : Purely created magenta color contains 44% of yellow

html - 链接到带有 iFrame 的页面以加载不同的 PDF 文件

python - 如何在 Python 中获取多个多行输入变量?

python - 抓取 html 表,如何使信息具有相似的结构

python - 将 unhexlify 从 Python 2.7 移植到 Python 3.5

python - 使用 Python 突出显示 PDF 中的文本

python - 打印 PDF 并在打印完成后删除文件

pdf - 使用 pypdf 更改 pdf 文件的元数据

python-3.x - 无法使用 Pypdf 读取 pdf 文件。它以字节码显示输出