This guide will take you through the steps necessary to integrate PSPDFKit into your Java application. By the end, you’ll be able to load a PDF document into your application using the PSPDFKit API.
PSPDFKit Library for Java can be evaluated without a trial license key, but with certain limitations (such as a red watermark added to documents). To evaluate without limitations, get a trial key.
PSPDFKit does not collect any data during your evaluation of the SDK.
Please select the build system you’re using:
Gradle Build System
-
In your top-level
build.gradle
file, add the PSPDFKit Maven repository:
allprojects {
repositories {
maven {
url 'https://my.pspdfkit.com/maven/'
}
}
}
-
In the depending module’s
build.gradle
file, add the PSPDFKit dependency:dependencies { implementation 'com.pspdfkit:libraries-java:1.5.0' }
-
Add the OCR dependency (optional). This is only necessary if you plan to use the OCR feature.
To use the PSPDFKit OCR feature with the PSPDFKit Java Library, a separate package, libraries-java-ocr
, is required.
Add the new package dependency to your build.gradle
file:
dependencies {
...
implementation 'com.pspdfkit:libraries-java-ocr:1.5.0'
}
Maven Build System
-
In your top-level
pom.xml
file, add the PSPDFKit Maven repository:
<repositories> <repository> <id>pspdfkit</id> <name>PSPDFKit Maven</name> <url>https://my.pspdfkit.com/maven/</url> </repository> </repositories>
-
In the depending module’s
pom.xml
file, add the PSPDFKit dependency:
<dependencies> <dependency> <groupId>com.pspdfkit</groupId> <artifactId>libraries-java</artifactId> <version>1.5.0</version> </dependency> </dependencies>
-
Add the OCR dependency (optional). This is only necessary if you plan to use the OCR feature.
To use the PSPDFKit OCR feature with the PSPDFKit Java Library, a separate package, libraries-java-ocr
, is required.
Add the new package dependency to your project pom.xml
file:
<dependencies> ... <dependency> <groupId>com.pspdfkit</groupId> <artifactId>libraries-java-ocr</artifactId> <version>1.5.0</version> </dependency>
Using the PSPDFKit Java Library
-
Now that the PSPDFKit Java Library is added, you can use the SDK in your application. You need to initialize the SDK prior to calling any other PSPDFKit method. If you have a license key (either a trial key or a production key), you can use the
initialize
method. You can also use theinitializeTrial
method to get started right away:
public void initializePSPDFKit() throws PSPDFKitInitializeException { PSPDFKit.initializeTrial(); }
@Throws(PSPDFKitInitializeException::class) fun initializePSPDFKit() : Void { PSPDFKit.initializeTrial(); }
-
Load a document with:
File file = new File("path/to/document.pdf"); PdfDocument document = PdfDocument.open(new FileDataProvider(file));
val file = File("path/to/document.pdf") val document = PdfDocument.open(FileDataProvider(file))
-
Once you have a document loaded, you can use the rest of the library. See the API docs and guides for more information, or try out the Catalog examples (see below).
Building and Running the Catalog App
The PSPDFKit Java Library comes with an example application called the Catalog app, which contains many useful examples for exploring the different features of PSPDFKit and getting started quickly. You can find the app in the Example
folder of the SDK ZIP file.
To build and run the Catalog app, follow these steps.
-
Extract
PSPDFKit-Libraries-java_binary-{version}.zip
to your desired location andcd
into the root of its directory. -
cd
into the Catalog (cd catalog
). -
Build and run the Catalog application:
./gradlew runJava
The PSPDFKit Java Library comes with an example application called the Catalog app, which contains many useful examples for exploring the different features of PSPDFKit and getting started quickly. You can find the app in the Example
folder of the SDK ZIP file.
To build and run the Catalog app, follow these steps.
-
Extract
PSPDFKit-Libraries-java_binary-{version}.zip
to your desired location andcd
into the root of its directory. -
cd
into the Catalog (cd catalog
). -
Build and run the Catalog application:
./gradlew runJava
The PSPDFKit Java Library comes with an example application called the Catalog app, which contains many useful examples for exploring the different features of PSPDFKit and getting started quickly. You can find the app in the Example
folder of the SDK ZIP file.
To build and run the Catalog app, follow these steps.
-
Extract
PSPDFKit-Libraries-java_binary-{version}.zip
to your desired location andcd
into the root of its directory. -
cd
into the Catalog (cd catalog
). -
Build and run the Catalog application:
gradlew.bat runJava