有没有办法从 pdf 文档中逐行获取文本或使用任何库和语言获取行。 我可以使用java中的这3个lib pdfbox、itext、aspose-pdf从pdf文档中逐页获取文本。
最佳答案
使用 PyMuPDF,这是最简单的方法:
import fitz # PyMuPDF
doc = fitz.open("input.pdf")
for page in doc:
i = 0
blocks = page.get_text("blocks", sort=True) # text organized in paragraphs
for block in blocks:
for line in block[4].splitlines():
print(f"Page {page.number}, line {i}: '{line}'")
i += 1
Every block is a tuple of 4 boundary box coordinates, followed by the string comprising the text of the paragraph.
关于python - 从pdf文档中提取文本时是否可以获取行号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76437736/