从pdf中检索特定部分的数据

时间:2013-07-31 07:10:44

标签: java extraction

我需要从pdf文件中检索一些与关键字相关的数据。以下是关键词:标题,pdf的范围,谁提出了pdf,版本,摘要,状态,监管。

是否有任何工具可以从pdf中检索数据? 在此先感谢

3 个答案:

答案 0 :(得分:2)

你可以使用PDFBox from Apache,说实话,我从来没有使用它,但在论坛上阅读了很多。

其他替代方案可以是iTextJPedal

如果您有兴趣,可以试试这些,但我相信,使用PDFBox,您将能够满足您的要求。

由于

答案 1 :(得分:0)

考虑Apache PDFBox

从PDF中提取文本,然后解析它以获取所需的信息。它是免费的。

还有另一个工具,iText但如果您正在开展商业项目,则需要在iText上购买许可证。

答案 2 :(得分:0)

使用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));
    } 
}

这里我尝试了这个来提取部分。这可能会对你有帮助。