我有pdf文档。我很清楚如何从中提取文本。
我不仅需要提取文本,还需要提取与此文本相关的坐标。
这是我的密码
from PyPDF2 import PdfReader
pdf_path = 'docs/doc_3.pdf'
pdf = PdfReader(pdf_path)
page_1_object = pdf.getPage(1)
page_1_object.extractText().split("\n")结果是:
['Creating value for all stakeholders',
'Anglo\xa0American is re-imagining mining to improve people’s lives.']我需要与摘录段落相关的几何图形。例如,可能是这样的:
['Creating value for all stakeholders', [1,2,3,4,]]
'Anglo\xa0American is re-imagining mining to improve people’s lives.', [7,8,9,10]]我怎么能做到呢?
谢谢,
发布于 2022-08-28 00:43:35
目前,该功能不是PyPDF2特性,它能够像显示extractText()那样解析内容,但不保持单独的字形xy位置,也不输出行坐标。
python中还有其他方法可以提取单个或多个字母组,这些字母构成单词。
使用shell命令(如poppler /与来自PyPDF2的文本"word“一起使用)是可能的,但是通常使用另一个PyPDF2(如PyMuPDF )运行,这里有这样一篇文章,https://pyquestions.com/find-text-position-in-pdf-file用于突出显示PyMuPDF输入。
达到目标的最常见的方法可能就像这里描述的那样,How to extract text and text coordinates from a PDF file?
https://stackoverflow.com/questions/73503313
复制相似问题