Skip to main content

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:

  1. 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.

Get started with a sample project

This Java sample project demonstrates how to extract all images and image masks from a PDF document.

Compile and run the sample

Switch between the following tabs to display steps for the CLI (Maven or Gradle), Eclipse IDE, or IntelliJ IDEA. To compile and run the sample, follow these steps:

  1. Download a sample project, and then unzip the file.

  2. Locate your license key. For more information, review Find the license key.

  3. In the lib/src/main/java/ToolboxImageExtraction/ToolboxImageExtraction.java file, 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.

  1. In the command line, navigate to the root directory of the unzipped sample project.

  2. Create an output directory:

    mkdir output_images
  3. Build and run the sample to extract all images and image masks from the sample PDF file ImageCollection.pdf to the output directory output_images:

    mvn clean install
    mvn exec:java -Dexec.mainClass="ToolboxImageExtraction.ToolboxImageExtraction" -Dexec.args="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 this snippet with a placeholder and compare it to the last step of the previous procedure:

mvn exec:java -Dexec.mainClass="ToolboxImageExtraction.ToolboxImageExtraction" -Dexec.args="INPUT_FILE OUTPUT_DIRECTORY"
note

You can apply a similar procedure described in this tutorial for other code samples. For more information, see Code samples page.

Integrate the Toolbox add-on into your application

Integrate and initialize the Toolbox add-on into your application by following the instructions in these sections.

Add the Toolbox add-on to your project

To add the Toolbox add-on to your project, use one of the following methods:

The Toolbox add-on for Java is available on Maven Central. To add the Toolbox add-on for Java to your project, add the following to your pom.xml:

<dependency>
<groupId>com.pdftools</groupId>
<artifactId>toolbox</artifactId>
<version>1.12.0</version>
</dependency>

The dependency includes native binaries for all supported platforms, which are loaded automatically at runtime.

Initialize the Toolbox add-on

The Toolbox add-on always requires a license key to operate (unlike the Pdftools SDK).

Getting a license key

Without a valid license key, the Toolbox add-on returns an error. Get in touch with the Pdftools sales team through the Contact page to get a full license.

To initialize the Toolbox add-on with your license key, follow these steps:

  1. Locate your license key. For more information, review Find the license key.

  2. Before you call any function of the Toolbox add-on, first call the Sdk.initialize method.

    Sdk.initialize("insert-license-key-here", null);

    Replace insert-license-key-here with the value of your license key. Use the license key in the same format as you copied it. Include the less-than (<) and greater-than (>) signs.

To get a code sample with the Sdk.initialize method that you can use as a reference for your code, follow these steps:

  1. On the Code samples page, download and unzip a Java code sample. For example: Download Extract all images and image masks from a PDF sample.
  2. Unzip the file, and then find the Sdk.initialize method in the main Java file of the sample. For example: Extract all images and image masks from a PDF sample includes the Sdk.initialize method in the lib/src/main/java/ToolboxImageExtraction/ToolboxImageExtraction.java file.
  3. Replace insert-license-key-here with your license key.

Implement your use case

  • Find more use cases and sample projects on the Code samples page.
  • For more technical information about the Toolbox add-on for Java, consult the Java technical notes.