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 Pdftools SDK into your application with the Java programming language.

tip

Try the Pdftools SDK without a license key for free.

Prerequisites

The Pdftools SDK for Java requires Java version 8 or higher.

Get started with a sample project

Learn how to use the Pdftools SDK using a Java sample project and convert a PDF file to an image.

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. In the command line, navigate to the root directory of the unzipped sample project.

  3. Build and run the sample:

    mvn clean install
    mvn exec:java -Dexec.mainClass="PdfToolsPdf2ImgSimple.PdfToolsPdf2ImgSimple" -Dexec.args="PdfPrimerWhitepaper.pdf tiff_output.tiff"

The code sample takes:

  • The input and output files are represented as a file name or a file path with the file name.
  • Both file paths (input and output) can be relative or absolute.

Compare the command syntax with a placeholder to the previous procedure:

mvn exec:java -Dexec.mainClass="PdfToolsPdf2ImgSimple.PdfToolsPdf2ImgSimple" -Dexec.args="INPUT_FILE OUTPUT_FILE"
note

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 Pdftools SDK into your application.

Add the SDK to your project

To add the Pdftools SDK to your project, use one of the following methods:

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

<dependency>
<groupId>com.pdftools</groupId>
<artifactId>pdftools-sdk</artifactId>
<version>1.15.0</version>
</dependency>

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

Optional: Initialize the SDK

Learn how to remove watermarked output of the Pdftools SDK using a valid license key.

tip

You can try the Pdftools SDK without a license key for free. This section is optional if you want to evaluate this SDK. Initialization removes watermarks added to output files and makes the SDK ready for production environments.

Getting a license key

Contact the Pdftools sales team through the Contact page to get a full license. For additional information, review the Pdftools SDK license management.

To remove watermarks, follow these steps:

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

  2. Before you call any function of the Pdftools SDK, first call the Sdk.initialize method.

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

    Replace the insert-license-key-here with the value of your license key. Include the less-than (<) and greater-than (>) signs.

To get a working 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 Convert PDF to image sample.
  2. Unzip the file, and then find the Sdk.initialize method in the main Java file of the sample. For example: Convert PDF to image sample includes the Sdk.initialize method in the lib/src/main/java/PdfToolsPdf2ImgSimple/PdfToolsPdf2ImgSimple.java file.
  3. Uncomment the method and 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 Pdftools SDK for Java, consult the Java technical notes.
  • If you need to configure a proxy, review Configure proxy documentation section.