Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PDFBOX OutOfMemory

I am facing a big issue with PDFBOX: I tried to load a file of 10Mb (test.pdf) and i needed 400 Mb to load it on JVM: Here is the code sample :

    final File mainFile = new File(
            "C:/test.pdf");
    System.out.println("File size: " + mainFile.length());
    try {
        PDDocument doc = PDDocument.load(mainFile);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    System.out.println("Used Memory: " +  (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()));
}

Is that normal ?

like image 942
brianbro Avatar asked Mar 15 '26 13:03

brianbro


1 Answers

No, that is not normal.

I notice you hadn't closed the document (required, please read the documentation). Perhaps that accumulated in multiple runs. You also don't mention memory usage before loading the document.

like image 127
ipavlic Avatar answered Mar 18 '26 03:03

ipavlic



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!