读取PDF文档内容

main
chenwei 1 year ago
commit cbee9c9b67

@ -0,0 +1,41 @@
package devUtil.pdfUtil;
import java.io.File;
import java.io.IOException;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.text.PDFTextStripper;
/**
* PDF
*/
public class PdfUtil {
/**
* PDF
*/
public String getPdfCharacter(String filePath, String fileName) {
String result = "";
try {
// 加载PDF文档
PDDocument document = PDDocument.load(new File(filePath + File.separator + fileName));
// 创建一个PDF文本提取器
PDFTextStripper pdfStripper = new PDFTextStripper();
// 提取文本
result = pdfStripper.getText(document);
// 关闭文档
document.close();
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
}
Loading…
Cancel
Save