Link
Skip to main content

How to setup in NetBeans

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.

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

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 NetBeans:

If you haven’t already, go to NetBeans website and download the latest version of NetBeans:

NetBeans official website

Step 2 - Create a project:

Once installed, open up NetBeans. Go to ‘New project’ then create a Java application with Ant. (This will give you all the basics you need and is great for when starting out with JPedal) Click ‘Next’ and name your project, then click ‘Finish’.

create a project

Create a ‘lib’ directory in the project 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 ‘Libraries’, click the plus symbol and ‘Add JAR/Folder’.

project properties panel

Now go to the lib folder where the JPedal jar is, click on the jar, click ‘Open’, then click ‘OK’.

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 File’.

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