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.
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:
- CLI: Maven
- CLI: Gradle
- Eclipse IDE
- IntelliJ IDEA
-
Clone the sdk-examples-java repository:
git clone https://github.com/pdf-tools/sdk-examples-java.git -
Navigate to the
Pdf2ImgSimplecode example:cd sdk-examples-java/Pdf2ImgSimple -
Build and run the sample:
mvn clean installmvn 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"
-
Clone the sdk-examples-java repository:
git clone https://github.com/pdf-tools/sdk-examples-java.git -
Navigate to the
Pdf2ImgSimplecode example:cd sdk-examples-java/Pdf2ImgSimple -
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 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.
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"
-
Clone the sdk-examples-java repository:
git clone https://github.com/pdf-tools/sdk-examples-java.git -
Open Eclipse and navigate to File > Import.
-
Select Maven > Existing Maven Projects (or Gradle > Existing Gradle Project) and click Next.
-
Browse to
sdk-examples-java/Pdf2ImgSimpleand click Finish. -
In the Package Explorer, locate the main class containing the
mainmethod. -
Right-click the file and select Run As > Java Application.
-
Clone the sdk-examples-java repository:
git clone https://github.com/pdf-tools/sdk-examples-java.git -
Open IntelliJ IDEA and navigate to File > Open.
-
Select
sdk-examples-java/Pdf2ImgSimpleand 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’.
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.
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:
- 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.16.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.16.0'
The dependency includes native binaries for all supported platforms, which are loaded automatically at runtime.
- Download
pdftools-sdk-1.16.0.jarfrom Maven Central (sources jar, javadoc jar). - Download
pdftools-sdk-native-1.16.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.
Initialization removes watermarks from output files and readies the SDK for production. Without a license key, output files carry a watermark.
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:
-
Find your license key. For more information, review Find the license key.
-
Call
Sdk.initializeonce at application startup, before any other Pdftools SDK method call:Sdk.initialize("YOUR_LICENSE_KEY");Replace
YOUR_LICENSE_KEYwith 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:
- Clone the sdk-examples-java repository and navigate to a sample directory. For example,
sdk-examples-java/Pdf2ImgSimple. - Open the main Java file and find the commented-out
Sdk.initializecall. For example, the Pdf2ImgSimple Java sample includes it inlib/src/main/java/PdfToolsPdf2ImgSimple/PdfToolsPdf2ImgSimple.java. - 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.