public static void main(String[] args) throws Exception{
String textFromPdf = getTextFromPdf("D:/download/upload/courseResource/00e90904-f6c3-4a3e-a042-f9dde5fba790.pdf");
System.out.println(textFromPdf);
}
public static String getTextFromPdf(String filePath) throws Exception {
String result = null;
FileInputStream is = null;
PDDocument document = null;
is = new FileInputStream(filePath);
PDFParser parser = new PDFParser(new RandomAccessBuffer(is));
parser.parse();
document = parser.getPDDocument();
PDFTextStripper stripper = new PDFTextStripper();
result = stripper.getText(document);
if (is != null) {
is.close();
is = null;
}
if (document != null) {
document.close();
document = null;
}
return result;
}
Java解析PDF文檔中文本內容
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.