How to setup in Eclipse
JPedal is a Java PDF library that provides functionality to view, print, rasterize and extract content from 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 project.
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.
Step 2 - Clone the repository:
Go to the GitHub repository of our example and click on ‘Code’.
Either:
- Copy the URL under ‘Clone with HTTPS’
Then in a command line run ‘git clone <url >’
For example: ‘git clone https://github.com/idrsolutions/jpedal-code-example.git’
Or
- Click ‘Download ZIP’ and extract zip to a path of your choice.
In the new project location, create a ‘lib’ directory, which will be used to store dependencies.
Step 3 - Create a project:
Open up Eclipse, click ‘File’ -> ‘New’ -> ‘Java Project’. Add a project name. Untick ‘Use default location’ and use ‘Browse’ to find the location of the cloned repository. Click ‘Finish’.
Step 4 - 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’.
Click on ‘Add JARs…’, go to the lib folder, select the JPedal jar, click ‘Ok’, then ‘Apply and Close’.
Step 5 - Start coding:
public static void main(String[] args) {
try {
pdfToImage();
// pdfViewer();
// extractWords();
// extractImages();
} catch (final Exception e) {
e.printStackTrace();
}
}
Change the parameters of the action to point to the correct input/output
public static void pdfToImage() throws PdfException {
ConvertPagesToImages.writeAllPagesAsImagesToDir("inputFile.pdf",
"outputFolder", "png", 1.33f);
}
Click the run button.
Want to add more to your project?
Check out the following tutorials for more information to see what JPedal can do for you:
- Convert PDF to an Image
- View PDF in Java
- Print PDF from Java
- Search the Text in PDF
- Extract Text from PDF
- Extract Images from PDF
- Extract Metadata from PDF
- Edit PDF Form Annotations