Linux下PDF书签的 添加/提取

在Linux下,一直没有称手的为PDF 添加/导出 书签的小工具,最近基于Pymupdf写了一个

usage: 
    pdf2outline -b bookmarks.txt -i input.pdf
    pdf2outline -b bookmarks.txt -i input.pdf -extract
    pdf2outline [-h] -b bookmarks.txt [-n 0] [-collapse 1] -i input.pdf [-o output.pdf] [-extract]

一个为PDF文件 添加/提取 书签的小程序
options:
  -h, --help        show this help message and exit
  -b bookmarks.txt  bookmarks text filename
  -n 0              page bias number, a integer
  -collapse 1       this will collapse all items with a hierarchy level greater than n
  -i input.pdf      input PDF filename
  -o output.pdf     output PDF filename
  -extract          extract input PDF's bookmarks

最终页码 = page + page_bias

bookmarks.txt 说明    每行前面用 Tab 符的个数表示层级,中间亦用 Tab 分隔    每行可以二个或三个参数,如:    
    title1      page1
        title2  page2
        title3  page3   height1
    title4      page4   height2

    其中的height是书签跳转到page页面的位置
预设参数如下:
    页数偏移默认为0 (即 -n 0);
    默认全部标签收起 (即 -collapse 1);    
    默认height为0;    
    没输出文件名时默认在原文件上修改    

脚本如下,需用自取:
pdf2outline.tar.gz (2.0 KB)

4 个赞

PyMuPDF这个库不错,再借助ChatGPT,想要的基本功能聊聊天大都能实现。

1 个赞