Link
Skip to main content

How to setup in Eclipse

JPedal is a Java PDF library that allows developers to view, print, rasterize, extract content from, and edit PDF files in their own Java applications. Whilst the library has a multitude of classes to access these features, you will likely want to add the functionality to your own system or maybe expand on what is provided. This can be done with an IDE such as Eclipse.

This tutorial will show you how to set up a project and start using JPedal in Eclipse using a sample JPedal class.

Please note: A trial or full copy of the JPedal jar is needed. You can download the trial jar from here.

Step 1 - Download and install Eclipse:

If you haven’t already, download the latest copy of Eclipse. download Eclipse

Step 2 - Create a project:

Open up Eclipse, click ‘File’ -> ‘New’ -> ‘Java Project’. Add a project name and select a JRE of Java 17 or above. Untick ‘Create module-info.java file’ (or see using JPedal with Java modules), then click ‘Finish’.

In the new project, create a ‘lib’ directory, which will be used to store dependencies.

Step 3 - Add JPedal dependency (trial or full version):

Now you have a project, find your copy of the JPedal jar file, add it to the ‘lib’ directory.

Right-click on your project and go to ‘Properties’. Then go to ‘Java Build Path’ -> ‘Libraries’. panel from right click

Click on ‘Add JARs…’, go to the lib folder, select the JPedal jar, click ‘Ok’, then ‘Apply and Close’.

properties window

Step 4 - Start coding:

Create a new class called JPedalExamples in the project’s src folder and paste in the following code:

import org.jpedal.examples.images.ConvertPagesToImages;
import org.jpedal.examples.images.ExtractImages;
import org.jpedal.examples.text.ExtractTextInRectangle;
import org.jpedal.examples.viewer.Viewer;
import org.jpedal.examples.viewer.ViewerCommands;
import org.jpedal.exception.PdfException;

public class JPedalExamples {

    public static void main(String[] args) {
        try {
            pdfToImage();
//            pdfViewer();
//            extractText();
//            extractImages();
        } catch (final PdfException e) {
            e.printStackTrace();
        }
    }

    public static void pdfToImage() throws PdfException {
        ConvertPagesToImages.writeAllPagesAsImagesToDir("inputFile.pdf", "outputFolder", "png", 1.33f);
    }

    public static void pdfViewer() {
        final Viewer viewer = new Viewer();
        viewer.setupViewer();
        viewer.executeCommand(ViewerCommands.OPENFILE, "inputFile.pdf");
    }

    public static void extractText() throws PdfException {
        ExtractTextInRectangle.writeAllTextToDir("inputFile.pdf", null, "outputFolder", -1,
                ExtractTextInRectangle.OUTPUT_FORMAT.TXT, false);
    }

    public static void extractImages() throws PdfException {
        ExtractImages.writeAllImagesToDir("inputFile.pdf", "outputFolder", "png", true, false);
    }
}

Change inputFile.pdf and outputFolder to the full paths of your input file and output directory, then uncomment the method you would like to run in main.

Right-click on JPedalExamples.java and select ‘Run As’ -> ‘Java Application’.

Want to add more to your project?

Check out the following tutorials for more information to see what JPedal can do for you:


Why JPedal?

  • Actively developed commercial library with full support and no third party dependencies.
  • Process PDF files up to 3x faster than alternative Java PDF libraries.
  • Simple licensing options and source code access for OEM users.

Learn more about JPedal

Start Your Free Trial


Customer Downloads

Select Download