user2677034
user2677034

Reputation: 694

Apache PDFBox cannot find class 'Loader'. Why?

I'm using either pdfbox-app-2.0.18.jar or pdfbox-app-2.0.17.jar.

From the example here, I have this code below :

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

}

After executing this code, I'm getting this error given below :

org.apache.pdfbox.Loader is not found 

How to resolve this issue ?

Upvotes: 14

Views: 10356

Answers (3)

Anish B.
Anish B.

Reputation: 16539

Loader class is never introduced in version 2.x or lower. So, you can't use it.

Alternatively, you can use load() method from PDDocument class to load PDF files.

Modify to this :

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

        // code 

}

Read this :- https://pdfbox.apache.org/2.0/migration.html

Upvotes: 11

The PDDocument class will represent the PDF document that is being processed. Its load() method will load in the PDF file specified by the File object :

PDDocument document = PDDocument.load(new File("path/to/pdf"));

Upvotes: 5

zomega
zomega

Reputation: 2326

The Loader class has been added January 25, 2020. SVN log

It's not part of version 2.0.18, as it is not in this file: pdfbox-2.0.18-src.zip

So this class is simply too new and that's why you cannot use it!

Upvotes: 7

Related Questions