如何使用Java阅读PDF文件? [英] How to read PDF files using Java?

查看:26
本文介绍了如何使用Java阅读PDF文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Java 从 PDF 文件中读取一些文本数据.我该怎么做?

I want to read some text data from a PDF file using Java. How can I do that?

推荐答案

PDFBox 是我为此找到的最好的库,如果您只是进行基本的文本提取,它非常全面且非常易于使用.示例可以在此处找到.

PDFBox is the best library I've found for this purpose, it's comprehensive and really quite easy to use if you're just doing basic text extraction. Examples can be found here.

它在页面上进行了解释,但需要注意的一件事是使用 setStartPage() 和 setEndPage() 时的开始和结束索引两者都包含在内.我第一次跳过了那个解释,然后我花了一段时间才意识到为什么每次调用我都会返回超过一页!

It explains it on the page, but one thing to watch out for is that the start and end indexes when using setStartPage() and setEndPage() are both inclusive. I skipped over that explanation first time round and then it took me a while to realise why I was getting more than one page back with each call!

Itext 是另一种也适用于 C# 的替代方案,尽管我个人从未使用过它.它比 PDFBox 级别更低,因此如果您只需要基本的文本提取,则不太适合这项工作.

Itext is another alternative that also works with C#, though I've personally never used it. It's more low level than PDFBox, so less suited to the job if all you need is basic text extraction.

这篇关于如何使用Java阅读PDF文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆