我想提取一些pdf文件中指定的文本和文本位置。
我知道xpdf和mupdf可以解析pdf文件,所以我认为它们可以帮助我完成这项任务。
但是如何使用这两个库来获取文本位置呢?
发布于 2011-12-02 17:29:25
Mupdf附带了几个工具,其中一个是pdfdraw。
如果您使用带有-tt选项的pdfdraw,它将生成一个包含所有字符及其确切位置信息的XML。
从那里你应该能够找到你需要的东西。
发布于 2018-01-16 06:04:21
如果您不介意为MuPDF使用Python绑定,这里有一个使用PyMuPDF的Python解决方案(我是它的开发人员之一):
import fitz # the PyMuPDF module
doc = fitz.open("input.pdf") # PDF input file
page = doc[n] # page number n (0-based)
wordlist = page.getTextWords() # gives you a list of all words on the
# page, together with their position info (a rectangle containing the word)
# or, if you only are interested in blocks of lines belonging together:
blocklist = page.getTextBlocks()
# If you need yet more details, use a JSON-based output, which also gives
# images and their positions, as well as font information for the text.
tdict = json.loads(page.getText("json"))如果你感兴趣,我们在GitHub上。
https://stackoverflow.com/questions/7512674
复制相似问题