首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PdfBox从pdf中提取具有相同字体的文本

PdfBox从pdf中提取具有相同字体的文本
EN

Stack Overflow用户
提问于 2013-09-18 16:39:51
回答 1查看 2K关注 0票数 1

我需要从pdf中提取一段文字。本文具有与特征相同的字体族。有什么想法吗?干杯

编辑:,让我用另一种方式问这个问题:我如何才能从pdf页面中提取出“粗体”文本?

EN

回答 1

Stack Overflow用户

发布于 2014-01-14 21:57:56

代码语言:javascript
复制
public String pdftoText(String fileName){
    try {
        File f = new File(fileName);
        if (!f.isFile()) {
            System.out.println("File not exist.");
            return null;
        }
        parser = new PDFParser(new FileInputStream(f));
        parser.parse();
        cosDoc = parser.getDocument();
        pdfStripper = new PDFTextStripper();
        pdDoc = new PDDocument(cosDoc);
        parsedText = pdfStripper.getText(pdDoc);
        cosDoc.close();
        pdDoc.close();
        return parsedText;
    } catch (IOException ex) {
        Logger.getLogger(PDFTextParser.class.getName()).log(Level.SEVERE, null, ex);
        return null;
    }
}

运行前的:将pdfbox.jar添加到项目

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

https://stackoverflow.com/questions/18877749

复制
相关文章

相似问题

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