Skip to main content

Get started with Java

This guide walks you through the steps to use a code example, 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.

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 code example. The Pdf2ImgSimple example converts a PDF file to an image. Use similar steps to run any other code example from the sdk-examples-java repository.

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. Clone the sdk-examples-java repository:

    git clone https://github.com/pdf-tools/sdk-examples-java.git
  2. Navigate to the Pdf2ImgSimple code example:

    cd sdk-examples-java/Pdf2ImgSimple
  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 example 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"

The sample runs without a license key, and the output carries a watermark. To remove the watermark, open the main Java file (for example, lib/src/main/java/PdfToolsPdf2ImgSimple/PdfToolsPdf2ImgSimple.java) and uncomment the Sdk.initialize method call in main(). Replace the "insert-license-key-here" placeholder with your license key. Include the less-than (<) and greater-than (>) signs.

note

You can apply a similar procedure described in this tutorial for other code examples. 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.20.1</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

Initialization removes watermarks from output files and readies the SDK for production. Without a license key, output files carry a watermark.

Getting a license key

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

To remove watermarks, follow these steps:

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

  2. Call Sdk.initialize once at application startup, before any other Pdftools SDK method call:

    Sdk.initialize("YOUR_LICENSE_KEY");

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

To get a working reference with the Sdk.initialize method, follow these steps:

  1. Clone the sdk-examples-java repository and navigate to a sample directory. For example, sdk-examples-java/Pdf2ImgSimple.
  2. Open the main Java file and find the commented-out Sdk.initialize call. For example, the Pdf2ImgSimple Java sample includes it in lib/src/main/java/PdfToolsPdf2ImgSimple/PdfToolsPdf2ImgSimple.java.
  3. Uncomment the call and replace the "insert-license-key-here" placeholder with your license key.

Implement your use case​

  • Find more use cases and code examples 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.