Apache PDFBox 找不到类“Loader”。为什么?

use*_*034 8 java pdfbox

我正在使用pdfbox-app-2.0.18.jarpdfbox-app-2.0.17.jar

这里的示例中,我有以下代码:

try (FileOutputStream fos = new FileOutputStream(signedFile);
     PDDocument doc = Loader.loadPDF(inputFile)) {
    
     // code

}
Run Code Online (Sandbox Code Playgroud)

执行此代码后,我收到以下错误:

org.apache.pdfbox.Loader is not found 
Run Code Online (Sandbox Code Playgroud)

如何解决这个问题?

Ani*_* B. 6

Loaderclass 从未在 2.x 或更低版本中引入。所以,你不能使用它。

或者,您可以使用类中的load()方法PDDocument来加载 PDF 文件。

修改为:

try (FileOutputStream fos = new FileOutputStream(signedFile);
     PDDocument document = PDDocument.load(inputFile)) {

        // code 

}
Run Code Online (Sandbox Code Playgroud)

阅读:- https://pdfbox.apache.org/2.0/migration.html


zom*_*ega 6

Loader 类已于 2020 年 1 月 25 日添加。SVN 日志

它不是 2.0.18 版的一部分,因为它不在此文件中: pdfbox-2.0.18-src.zip

所以这个类太新了,这就是你不能使用它的原因!


小智 5

PDDocument班将代表正在处理PDF文档。它的load()方法将加载到 File 对象指定的 PDF 文件中:

PDDocument document = PDDocument.load(new File("path/to/pdf"));
Run Code Online (Sandbox Code Playgroud)