public static String getInfo(String pdfFilePath) {
HashMap<String, String> info = new HashMap<>();
PdfDocument document = null;
StringBuffer sb = new StringBuffer();
try (FileInputStream is = new FileInputStream(pdfFilePath)) {
PdfReader reader = new PdfReader(is);
int pages = reader.getNumberOfPages();
for (int i = 1; i <= pages; i++) {
String textFromPage = PdfTextExtractor.getTextFromPage(reader, i);
sb.append(textFromPage);
sb.append("\n");//读取第i页的文档内容
}
String s = sb.toString();
reader.close();
return s.replaceAll(" ","");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return StringUtils.EMPTY;
}