1、下载pdfbox-app-2.0.31.jar并导入到项目结构中
2.重点:实现选择本地PDF文件代码
//选择PDF文件
private void selectPdfFile() {
JFileChooser fileChooser = new JFileChooser();
int result = fileChooser.showOpenDialog(this);
if (result == JFileChooser.APPROVE_OPTION) {
File selectedFile = fileChooser.getSelectedFile();
extractDegreeGPA(selectedFile.getAbsolutePath());
}
}
extractDegreeGPA是我具体实现的功能,在下边
3.这里是我实现的具体提取功能,这里的PDF内容是课程学分成绩等,具体涉及到提取表格的某行列信息。
private void extractDegreeGPA(String filePath) {
try (PDDocument document = PDDocument.load(new File(filePath))) {
PDFTextStripper pdfStripper = new PDFTextStripper();
// 提取PDF中的文本
String text = pdf