-1

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?

Victor
  • 474
  • 5
  • 18
Ctech45
  • 496
  • 9
  • 17

2 Answers2

1

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!

Tilman Hausherr
  • 17,731
  • 7
  • 58
  • 97
0

Have you tried the steps detailed on the documentation:

Adding And Removing JARs in DrJava

A JAR file is a way of storing many (pre-compiled) Java classes. Below are instructions for adding and removing jar files from DrJava's resource locations. For more information on JAR files, see our JARs page and Using JAR Files: The Basics on Sun's site.

How to add a JAR

  1. When you download the jar, keep track of where you save it to
  2. Open DrJava
  3. Edit > Preferences
  4. Resource Locations (at left)
  5. In Extra Classpath, Add (browse and chose the new jar)
  6. Apply
  7. Okay
  8. Quit DrJava and re-open it in order for the change to take effect

enter image description here

Federico Piazza
  • 30,085
  • 15
  • 87
  • 123