首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何通过xpdf或mupdf获取指定的文本pos?

如何通过xpdf或mupdf获取指定的文本pos?
EN

Stack Overflow用户
提问于 2011-09-22 17:38:36
回答 2查看 2.7K关注 0票数 3

我想提取一些pdf文件中指定的文本和文本位置。

我知道xpdf和mupdf可以解析pdf文件,所以我认为它们可以帮助我完成这项任务。

但是如何使用这两个库来获取文本位置呢?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-12-02 17:29:25

Mupdf附带了几个工具,其中一个是pdfdraw

如果您使用带有-tt选项的pdfdraw,它将生成一个包含所有字符及其确切位置信息的XML

从那里你应该能够找到你需要的东西。

票数 1
EN

Stack Overflow用户

发布于 2018-01-16 06:04:21

如果您不介意为MuPDF使用Python绑定,这里有一个使用PyMuPDF的Python解决方案(我是它的开发人员之一):

代码语言:javascript
运行
复制
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上。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7512674

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档