python:PyPDF2 从PDF文件中提取目录

我发现 pypdf  和 pypdf2 的作者是同一人:Mathieu Fenniak 

pip install pypdf2 ;

  pypdf2-3.0.1-py3-none-any.whl (232 kB)

编写 pdf_read_dir.py  如下

# -*- coding: utf-8 -*-
""" pypdf2==3.0.1 从PDF中提取目录 """
import os
import sys
from PyPDF2 import PdfReader

#每个书签的索引格式
#{'/Title': '书签名', '/Page': '指向的目标页数', '/Type': '类型'}

# 查找指定的字符出现次数
def find_char(str1, char):
    cs = 0
    for c in str1:
        if c == char:
            cs += 1
    return cs
    
directory_str = ''
def bookmark_listhandler(list1):
    global directory_str
    for message in list1:
        if isinstance(message, dict):
            title = message['/Title'].strip()
            if title.startswith("Chapter"): 
                directory_str += '\n' + title + '\n'
            elif title[0:2] in ("序章
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值