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.
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:
- CLI: Maven
- CLI: Gradle
- Eclipse IDE
- IntelliJ IDEA
-
Download a sample project, and then unzip the file.
-
In the command line, navigate to the root directory of the unzipped sample project.
-
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"
-
Download a sample project, and then unzip the file.
-
In the command line, navigate to the root directory of the unzipped sample project.
-
Build and run the sample:
./gradlew run --args="PdfPrimerWhitepaper.pdf tiff_output.tiff"note- On Windows, use
gradlew(orgradlew.bat) instead of./gradlew. - On macOS and Linux, you may need to make the wrapper executable first:
chmod +x gradlew
- On Windows, use
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.
Review the following snippet with a placeholder and compare it to the last step of the previous procedure:
./gradlew run --args="INPUT_FILE OUTPUT_FILE"
- Download a sample project, and then unzip the file.
- Open Eclipse and navigate to File > Import.
- Select Maven > Existing Maven Projects (or Gradle > Existing Gradle Project) and click Next.
- Browse to the root directory of the unzipped sample project and click Finish.
- In the Package Explorer, locate the main class containing the
mainmethod. - Right-click the file and select Run As > Java Application.
- Download a sample project, and then unzip the file.
- Open IntelliJ IDEA and navigate to File > Open.
- Select the root directory of the unzipped sample project and click OK.
- When prompted, choose to import the project as a Maven or Gradle project.
- In the Project tool window, locate the main class containing the
mainmethod. - Right-click the file and select Run ‘PdfToolsPdf2ImgSimple’.
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:
- Maven
- Gradle
- Manual
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.
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 build.gradle:
implementation 'com.pdftools:pdftools-sdk:1.15.0'
The dependency includes native binaries for all supported platforms, which are loaded automatically at runtime.
- Download
pdftools-sdk-1.15.0.jarfrom Maven Central (sources jar, javadoc jar). - Download
pdftools-sdk-native-1.15.0.jarfrom Maven Central (native libraries). - Add both JARs to your project’s classpath.
Optional: Initialize the SDK
Learn how to remove watermarked output of the Pdftools SDK using a valid license key.
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.
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:
-
Locate your license key. For more information, review Find the license key.
-
Before you call any function of the Pdftools SDK, first call the
Sdk.initializemethod.Sdk.initialize("insert-license-key-here");Replace the
insert-license-key-herewith 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:
- On the Code samples page, download and unzip a Java code sample. For example: Download Convert PDF to image sample.
- Unzip the file, and then find the
Sdk.initializemethod in the main Java file of the sample. For example: Convert PDF to image sample includes theSdk.initializemethod in thelib/src/main/java/PdfToolsPdf2ImgSimple/PdfToolsPdf2ImgSimple.javafile. - Uncomment the method and replace
insert-license-key-herewith 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.