Как извлечь текст из файла PDF с помощью Apache PDFBox

Я хотел бы извлечь текст из данного файла PDF с Apache PDFBox.

Я написал этот код:

PDFTextStripper pdfStripper = null;
PDDocument pdDoc = null;
COSDocument cosDoc = null;
File file = new File(filepath);

PDFParser parser = new PDFParser(new FileInputStream(file));
parser.parse();
cosDoc = parser.getDocument();
pdfStripper = new PDFTextStripper();
pdDoc = new PDDocument(cosDoc);
pdfStripper.setStartPage(1);
pdfStripper.setEndPage(5);
String parsedText = pdfStripper.getText(pdDoc);
System.out.println(parsedText);

Однако я получил следующую ошибку:

Exception in thread "main" java.lang.NullPointerException
at org.apache.fontbox.afm.AFMParser.main(AFMParser.java:304)

Я добавил pdfbox-1.8.5.jar и fontbox-1.8.5.jar в путь к классам.

редактировать

я добавилSystem.out.println("program starts"); к началу программы.

Я запустил его, затем я получил ту же ошибку, как указано выше, иprogram starts не появился в консоли.

Таким образом, я думаю, что у меня есть проблема с путем класса или чем-то.

Спасибо.

Ответы на вопрос(5)

Ваш ответ на вопрос