如何用python提取pdf中包含图像的页面?

2024-05-28 23:23:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我有4000份pdf格式的扫描文档。每个pdf包含我要提取的kyc表单。每个pdf有40个几页。什么我们可以使用一些技术来获得图像的页码,因为只要有页码,就可以使用pdf2image提取页面。在

enter image description here

enter image description here

kyc表格将是相似的,并将有图像张贴。我把图像弄模糊了,但质量会更好


Tags: 文档图像表单pdf格式质量页面技术
1条回答
网友
1楼 · 发布于 2024-05-28 23:23:36

这是一种简单的方法,它扫描所有书签以找到匹配的对象,然后扫描每个页面,直到它与同一对象匹配。可能不是最优雅的方法,但应该能完成任务。在

from PyPDF2 import PdfFileReader
reader = PdfFileReader('D:\\Downloads\Sample.pdf')

# Scan outlines for bookmark containing KYC
outlines = reader.outlines
print(outlines)
for bookmark in outlines:
    print(bookmark['/Title'])
    print(bookmark['/Page'])
    if bookmark['/Title'] == 'KYC':
        mypage = bookmark['/Page']

# Scan page looking for the matching object        
print(reader.getNumPages())
for x in range(0, reader.getNumPages()): 
    apage = reader.getPage(x)
    print(apage)
    if apage == mypage:
        print('Eureka on page', x + 1)

相关问题 更多 >

    热门问题