Automatically integrate Nutrient Java SDK for PDF processing
This guide helps you seamlessly integrate Nutrient Java SDK, letting build tools automatically handle its download and updates for advanced PDF capabilities. By the end, you’ll be able to load a PDF document into your application using the Nutrient Java API.
Select the build system you’re using:
In your top-level
build.gradle
file, add the Nutrient Maven repository:allprojects {repositories {maven {url 'https://my.nutrient.io/maven/'}}}In the depending module’s
build.gradle
file, add the Nutrient dependency:dependencies {implementation 'com.pspdfkit:libraries-java:1.7.1'}Add the OCR dependency (optional). This is only necessary if you plan to use the OCR feature. To do that, a separate package,
libraries-java-ocr
, is required. Add the new package dependency to yourbuild.gradle
file:dependencies {...implementation 'com.pspdfkit:libraries-java-ocr:1.7.1'}
In your top-level
pom.xml
file, add the Nutrient Maven repository:<repositories><repository><id>pspdfkit</id><name>Nutrient Maven</name><url>https://my.nutrient.io/maven/</url></repository></repositories>In the depending module’s
pom.xml
file, add the Nutrient dependency:<dependencies><dependency><groupId>com.pspdfkit</groupId><artifactId>libraries-java</artifactId><version>1.7.1</version></dependency></dependencies>Add the OCR dependency (optional). This is only necessary if you plan to use the OCR feature. To do that, a separate package,
libraries-java-ocr
, is required. Add the new package dependency to your projectpom.xml
file:<dependencies>...<dependency><groupId>com.pspdfkit</groupId><artifactId>libraries-java-ocr</artifactId><version>1.7.1</version></dependency>
Using the Nutrient Java library
Now that the Nutrient library is added, you can use the SDK in your application. You need to initialize the SDK prior to calling any other method. Use the initializeTrial
method if you haven’t yet bought a license key, or the initialize
method if you have a key:
public void initializePSPDFKit() throws PSPDFKitInitializeException { PSPDFKit.initializeTrial();}
@Throws(PSPDFKitInitializeException::class)fun initializePSPDFKit() : Void { PSPDFKit.initializeTrial();}
Next, load a document:
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 Nutrient library comes with an example application called the Catalog app, which contains many useful examples for exploring the different features of Nutrient. You can find the app in the Example
folder of the SDK ZIP file(opens in a new tab).
To build and run the Catalog app, follow the instructions below.
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:
Terminal window ./gradlew runJava
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:
Terminal window ./gradlew runJava
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:
Terminal window gradlew.bat runJava