使用java逐行读取pdf文件



如何使用java逐行读取pdf文件,并将行写入。txt和。doc文件?

使用PDFBox

try{
PDDocument document = null; 
document = PDDocument.load(new File("test.pdf"));
document.getClass();
if( !document.isEncrypted() ){
    PDFTextStripperByArea stripper = new PDFTextStripperByArea();
    stripper.setSortByPosition( true );
    PDFTextStripper Tstripper = new PDFTextStripper();
    String st = Tstripper.getText(document);
    System.out.println("Text:"+st);
}
}catch(Exception e){
    e.printStackTrace();
}

你可以从这里下载

最新更新