我需要从pdf文件中检索一些与关键字相关的数据。这些是关键词:标题,pdf的范围,谁提出的pdf,版本,摘要,状态,监管机构。
有没有工具可以从pdf中检索数据?提前感谢
发布于 2013-07-31 15:21:05
你可以使用PDFBox from Apache,老实说,我从来没有用过它,但在论坛上读了很多关于它的文章。
其他替代方案可以是iText或JPedal。
如果你感兴趣,你可以试一试,但我相信使用PDFBox你将能够满足你的需求。
谢谢
发布于 2013-07-31 15:20:17
考虑Apache PDFBox
从PDF中提取文本,然后对其进行解析以获取所需信息。它是免费的。
此外,还有另一个工具iText,但如果您正在处理商业项目,则需要在iText上购买许可证。
发布于 2013-07-31 17:49:36
使用PDFBOX
public class PDFTextReader
{
static String pdftoText(String fileName) {
PDFParser parser;
String parsedText = null;
PDFTextStripper pdfStripper = null;
PDDocument pdDoc = null;
COSDocument cosDoc = null;
File file = new File(fileName);
if (!file.isFile()) {
System.err.println("File " + fileName + " does not exist.");
return null;
}
try {
parser = new PDFParser(new FileInputStream(file));
} catch (IOException e) {
System.err.println("Unable to open PDF Parser. " + e.getMessage());
return null;
}
try {
parser.parse();
cosDoc = parser.getDocument();
pdfStripper = new PDFTextStripper();
pdDoc = new PDDocument(cosDoc);
// pdfStripper.setParagraphStart(FIND_START_VALUE);
// pdfStripper.setParagraphEnd("FIND_END_VALUE);
parsedText = pdfStripper.getText(pdDoc);
} catch (Exception e) {
System.err
.println("An exception occured in parsing the PDF Document."
+ e.getMessage());
} finally {
try {
if (cosDoc != null)
cosDoc.close();
if (pdDoc != null)
pdDoc.close();
} catch (Exception e) {
e.printStackTrace();
}
}
return parsedText;
}
public static void main(String args[]){
System.out.println(pdftoText(FILEPATH));
}
}在这里,我尝试了这个方法来提取部分。这可能会对你有帮助。
https://stackoverflow.com/questions/17963852
复制相似问题