pdf 抽取

import pdfplumber
 
def extract_text_from_pdf(pdf_path):
    # 打开PDF文件
    with pdfplumber.open(pdf_path) as pdf:
        # 初始化一个空字符串来存储文本
        text = ""
        # 遍历每一页
        for page in pdf.pages:
            # 提取当前页的文本
            text += page.extract_text()

            text+='\n\n\n\n'
    return text
 
# 使用函数

import glob
tmps=glob.glob('bbb/*.pdf',recursive=True)



print(1)




t=''
t=''.join([extract_text_from_pdf(i) for i in tmps])

with open('输出.txt' ,'w') as f:
  f.write(t)

posted on 2025-07-09 12:06  张博的博客  阅读(10)  评论(0)    收藏  举报

导航