如何在camelot中跳过基于图像的页面?

问题描述 投票:0回答:1

我正在为多个具有多个页面的 pdf 运行 for 循环以提取多个表格。问题是,当我对多个 pdf 运行 for 循环时,如果有任何 pdf 在第 1 页或第 2 页包含基于图像的格式,并且表格分别从第 2 页或第 3 页开始,则 for 循环停止并显示以下错误。

\Anaconda3\lib\site-packages\camelot\parsers\lattice.py:411: UserWarning: page-1 is image-based, camelot only works on text-based pages.

\Anaconda3\lib\site-packages\camelot\parsers\lattice.py:411: UserWarning: page-2 is image-based, camelot only works on text-based pages.

我想要一个可以跳过任何基于图像的页面并继续循环下一页的解决方案。

python list for-loop tabula python-camelot
1个回答
0
投票

到目前为止,我唯一能做的解决方案是尝试从 pdf 中提取文本,如果没有,则它是基于图像的

def is_page_image_based(pdf_path, page_number):
     doc = fitz.open(pdf_path)
     page = doc.load_page(page_number)
     text = page.get_text()
     doc.close()
     return !bool(text.strip())
© www.soinside.com 2019 - 2024. All rights reserved.