疯狂

STANDING ON THE SHOULDERS OF GIANTS
posts - 481, comments - 486, trackbacks - 0, articles - 1
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

使用apache pdfbox读取pdf 实例

Posted on 2011-02-24 14:55 疯狂 阅读(2748) 评论(2)  编辑  收藏 所属分类: java apache项目
public static void main(String[] args) throws Exception {
    InputStream inputStream 
= new BufferedInputStream(
            
new FileInputStream(new File("d:\\work\\lt.pdf")));
    PDDocument pdfDocument 
= PDDocument.load(inputStream);
    StringWriter writer 
= new StringWriter();
    PDFTextStripper stripper 
= new PDFTextStripper();
    stripper.writeText(pdfDocument, writer);
    String contents 
= writer.getBuffer().toString();
    System.out.println(
"文档内容:"+contents);
    PDDocumentInformation documentInformation 
= pdfDocument.getDocumentInformation();
    System.out.println(
"标题:"+documentInformation.getTitle());
}

}
需要jar包:
pdfbox-1.4.0.jar
fontbox-1.4.0.jar

评论

# re: 使用apache pdfbox读取pdf 实例[未登录]  回复  更多评论   

2011-04-21 05:16 by water
利用本程序解决了我的问题。谢谢!

只有注册用户登录后才能发表评论。


网站导航: