java 使用java逐行读取pdf文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32628462/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 20:31:10 来源:igfitidea点击:
Read pdf file line by line using java
提问by pampa
How to read pdf file line by line using java, And write the lines in .txt and .doc file? Please mention the required .jar for the program.
如何使用java逐行读取pdf文件,并在.txt和.doc文件中写入行?请提及程序所需的 .jar。
回答by Vivek Aditya
Using PDFBox
使用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();
}
You can download it from here
你可以从这里下载