Search code examples
javapdfboxdrjava

package org.pdfbox.cos does not exist


I am trying to import and use PDFBox, but am having issues installing the jars I believe.

I am using Dr. Java, and I have added both the pdfbox-1.8.6.jar and the pdfbox-app-1.8.6.jar to my resource locations in my Extra Classpath.

However, it still is not recognizing the jars when I run the code:

import org.pdfbox.cos.COSDocument;
import org.pdfbox.pdfparser.PDFParser;

What other steps do I need to do in order for the jars to work?


Solution

  • Use the correct imports:

    import org.apache.pdfbox.cos.COSDocument;
    import org.apache.pdfbox.pdfparser.PDFParser;
    

    Additional hints:

    • pdfbox-app-1.8.6.jar contains the classes from pdfbox-1.8.6.jar, so you don't need pdfbox-1.8.6.jar too
    • if you want to load a document for rendering or text extraction, you won't need these two imports. Loading is done with

      import org.apache.pdfbox.pdmodel.PDDocument;

      PDDocument doc = PDDocument.loadNonSeq(new File(filename), null);

    To see how it is done, look at the examples in the source code. Good luck!