Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache PDFBox cannot find class 'Loader'. Why?

Tags:

java

pdfbox

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 ?

like image 980
user2677034 Avatar asked Feb 06 '26 14:02

user2677034


2 Answers

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

like image 144
Anish B. Avatar answered Feb 08 '26 03:02

Anish B.


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!

like image 32
zomega Avatar answered Feb 08 '26 02:02

zomega



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!