Get started with Java
This guide walks you through the steps to use a sample project, and then explains how to integrate the Toolbox add-on into your application with the Java programming language.
Request trial or full license
The Toolbox add-on requires a license key for both evaluation and full use. To request a license key, follow these steps:
- Reach out to the sales team through the Contact page and mark the Toolbox add-on as the product of your interest for a trial license.
If you already have a license key and you need to copy it, review Find the license key.
Prerequisites
The Toolbox add-on for Java requires Java version 8 or higher.
Getting started with a sample project
Learn how to use Toolbox add-on using a Java sample project and extract all images and image masks from a PDF document.
Compile and run the sample
To compile and run the sample, follow these steps:
-
Download a sample project, and then unzip the file.
-
Locate your license key. For more information, review Find the license key.
-
In the
ToolboxImageExtraction.javafile, replace the string"insert-license-key-here"with your license key:Sdk.initialize("insert-license-key-here", null);Use the license key in the same format as you copied it. Include the less-than (
<) and greater-than (>) signs. -
In the command line, navigate to the root directory of the unzipped sample project.
-
Create an output directory:
mkdir output_images -
Compile the Java source file:
- macOS and Linux
- Windows
javac -cp jar/com.pdftools.toolbox.jar:. ToolboxImageExtraction.javajavac -cp jar/com.pdftools.toolbox.jar;. ToolboxImageExtraction.java -
To extract all images and image masks from the sample PDF file
ImageCollection.pdfto the output directory/output_images, run the following command:- macOS and Linux
- Windows
java -cp jar/com.pdftools.toolbox.jar:bin:. ToolboxImageExtraction ImageCollection.pdf /output_imagesjava -cp jar/com.pdftools.toolbox.jar;bin;. ToolboxImageExtraction ImageCollection.pdf /output_images
The code sample takes:
- The input and output files represented as a file name, a file path with the file name, or the output directory.
- Both file paths (input and output) can be relative or absolute.
Review the following snippet with a placeholder and compare it to the last step of the previous procedure:
- macOS and Linux
- Windows
java -cp jar/com.pdftools.toolbox.jar:bin:. ToolboxImageExtraction INPUT_FILE OUTPUT_DIRECTORY
java -cp jar/com.pdftools.toolbox.jar;bin;. ToolboxImageExtraction INPUT_FILE OUTPUT_DIRECTORY
You can apply a similar procedure described in this tutorial for other code samples. For more information, see Code samples page.
Integrate the SDK into your application
Integrate and initialize the Toolbox add-on into your application by following the instructions in the following sections.
Add the SDK to your project
- Maven
- Manual
The Toolbox add-on for Java is available on Maven. To add the Toolbox add-on for Java to your project, select your operating system and system architecture and add the following to your pom.xml:
- linux-x64
- linux-arm64
- osx-arm64
- osx-x64
- win-x64
- win-x86
- win-arm64
<dependency>
<groupId>com.pdftools</groupId>
<artifactId>toolbox</artifactId>
<version>1.11.0</version>
</dependency>
<dependency>
<groupId>com.pdftools</groupId>
<artifactId>toolbox</artifactId>
<version>1.11.0</version>
<classifier>linux-x64</classifier>
<type>so</type>
</dependency>
<dependency>
<groupId>com.pdftools</groupId>
<artifactId>toolbox</artifactId>
<version>1.11.0</version>
</dependency>
<dependency>
<groupId>com.pdftools</groupId>
<artifactId>toolbox</artifactId>
<version>1.11.0</version>
<classifier>linux-arm64</classifier>
<type>so</type>
</dependency>
<dependency>
<groupId>com.pdftools</groupId>
<artifactId>toolbox</artifactId>
<version>1.11.0</version>
</dependency>
<dependency>
<groupId>com.pdftools</groupId>
<artifactId>toolbox</artifactId>
<version>1.11.0</version>
<classifier>osx-arm64</classifier>
<type>dylib</type>
</dependency>
<dependency>
<groupId>com.pdftools</groupId>
<artifactId>toolbox</artifactId>
<version>1.11.0</version>
</dependency>
<dependency>
<groupId>com.pdftools</groupId>
<artifactId>toolbox</artifactId>
<version>1.11.0</version>
<classifier>osx-x64</classifier>
<type>dylib</type>
</dependency>
<dependency>
<groupId>com.pdftools</groupId>
<artifactId>toolbox</artifactId>
<version>1.11.0</version>
</dependency>
<dependency>
<groupId>com.pdftools</groupId>
<artifactId>toolbox</artifactId>
<version>1.11.0</version>
<classifier>win-x64</classifier>
<type>dll</type>
</dependency>
<dependency>
<groupId>com.pdftools</groupId>
<artifactId>toolbox</artifactId>
<version>1.11.0</version>
</dependency>
<dependency>
<groupId>com.pdftools</groupId>
<artifactId>toolbox</artifactId>
<version>1.11.0</version>
<classifier>win-x86</classifier>
<type>dll</type>
</dependency>
<dependency>
<groupId>com.pdftools</groupId>
<artifactId>toolbox</artifactId>
<version>1.11.0</version>
</dependency>
<dependency>
<groupId>com.pdftools</groupId>
<artifactId>toolbox</artifactId>
<version>1.11.0</version>
<classifier>win-arm64</classifier>
<type>dll</type>
</dependency>
- Download the Toolbox add-on for Java product kit, and then unzip the file.
- Add the
jarfile to your project’s classpath. - Copy the
libfolder containing the native binary files to your project, for example<project-dir>/lib.
Load the Toolbox add-on
The Toolbox add-on for Java requires you to load the underlying native binary files suitable for your operating system and system architecture at runtime.
- Maven
- Manual
There are two ways how to load the Toolbox add-on for Java with Maven:
-
If you are consuming Java libraries directly from the local Maven repository, load the native binary files using the following code:
- linux-x64
- linux-arm64
- osx-arm64
- osx-x64
- win-x64
- win-x86
- win-arm64
System.load(System.getProperty("user.home") + "/.m2/repository/com/pdftools/toolbox/1.11.0/toolbox-1.11.0-linux-x64.so");System.load(System.getProperty("user.home") + "/.m2/repository/com/pdftools/toolbox/1.11.0/toolbox-1.11.0-linux-arm64.so");System.load(System.getProperty("user.home") + "/.m2/repository/com/pdftools/toolbox/1.11.0/toolbox-1.11.0-osx-arm64.dylib");System.load(System.getProperty("user.home") + "/.m2/repository/com/pdftools/toolbox/1.11.0/toolbox-1.11.0-osx-x64.dylib");System.load(System.getProperty("user.home") + "/.m2/repository/com/pdftools/toolbox/1.11.0/toolbox-1.11.0-win-x64.dll");System.load(System.getProperty("user.home") + "/.m2/repository/com/pdftools/toolbox/1.11.0/toolbox-1.11.0-win-x86.dll");System.load(System.getProperty("user.home") + "/.m2/repository/com/pdftools/toolbox/1.11.0/toolbox-1.11.0-win-arm64.dll"); -
Alternatively, use the system library path:
-
Add the Toolbox add-on
libdirectory to the system library path.- Windows: Environment variable
PATH - Linux and macOS: Defined by
LD_LIBRARY_PATH - Or specify the path using the VM arg
-Djava.library.path=.
- Windows: Environment variable
-
Load the library using:
- linux-x64
- linux-arm64
- osx-arm64
- osx-x64
- win-x64
- win-x86
- win-arm64
System.loadLibrary("toolbox-1.11.0-linux-x64");System.loadLibrary("toolbox-1.11.0-linux-arm64");System.loadLibrary("toolbox-1.11.0-osx-arm64");System.loadLibrary("toolbox-1.11.0-osx-x64");System.loadLibrary("toolbox-1.11.0-win-x64");System.loadLibrary("toolbox-1.11.0-win-x86");System.loadLibrary("toolbox-1.11.0-win-arm64");
-
In the default configuration of the Toolbox add-on, the lib directory has the following structure:
lib
├── linux-x64