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文档中文本内容
最新推荐文章于 2024-05-14 04:33:59 发布