Integrating the PSPDFKit Java Library

This section explains the process of integrating PSPDFKit into your project. There are two methods that will be explained in the guide: syncing from a Maven repository, and downloading via our Customer Portal.

Sync from the PSPDFKit Maven Repository (Suggested)

PSPDFKit is a commercial product and it uses a license key to verify your PSPDFKit instance.

ℹ️ License Key and Maven Password

Existing customers: You need to retrieve the license key and Maven password from our Customer Portal. The steps are described below.

Demo customers: To get the license key and Maven password, request an evaluation version of PSPDFKit. If you already have, please follow the link in the demo email you received.

  1. Log in to the PSPDFKit Customer Portal using the credentials you received when purchasing PSPDFKit. You will see the list of all your purchased licenses.
  2. Retrieve the Maven password and integrate the code into your project:
    • Locate your license (e.g. PSPDFKit Java Library)
    • Click the Download PSPDFKit Java Library button next to it.
    • Click on the Use Gradle tab and follow the code snippet containing the Maven password for your build.gradle file.

Add the PSPDFKit Java Library Manually

Gradle Project

Integrating the PSPDFKit Java Library with Gradle is easy. A good example of this can be seen in the Catalog example distributed in the downloaded ZIP.

  • Create a folder within your project named libs.
  • In the downloaded ZIP file, there will be a JAR name, pspdfkit-*.*.*.jar. Copy this jar file into the libs folder you just created.
  • In your project’s build.gradle folder, add a dependency to the copied JAR file (replace the wildcards with the version number):
Copy
1
2
3
4
5
6
7
8
9
dependencies {
    ...
    implementation files('libs/pspdfkit-*.*.*.jar')

    // Required by PSPDFKit.
    implementation 'org.json:json:20180813'
    implementation 'org.apache.httpcomponents:httpclient:4.5.9'
    ...
}

Now your Gradle project will depend upon the PSPDFKit JAR. More information about declaring dependencies can be found in the Gradle documentation.

Maven Project

To use the PSPDFKit Java Library with Maven, it is first necessary to install the PSPDFKit JAR to a Maven repository. Only when this is done can it be a reference for a Maven project.

  • Within your project, using mvn on the command line, add the PSPDFKit JAR to a repository, replacing both the version (where necessary) and the path to the JAR and POM (extracted from PSPDFKit-Java-binary-*.*.*.zip):
1
mvn install:install-file -Dfile=/path/to/jar/pspdfkit-*.*.*.jar -DpomFile=/path/to/pom/pspdfkit-pom.xml

This will install the JAR to a local repository. It is also possible to publish this JAR remotely; please see the Maven guides if this is a requirement.

  • Add the PSPDFKit Java Library as a dependency of your project. In your project’s pom.xml, add the following, replacing the version with the target version:
Copy
1
2
3
4
5
6
7
8
9
...
<dependencies>
    <dependency>
        <groupId>com.pspdfkit.api</groupId>
        <artifactId>pspdfkit</artifactId>
        <version>*.*.*</version>
    </dependency>
</dependencies>
...

Now your Maven project will depend on the PSPDFKit JAR published to the chosen repository.

Use the PSPDFKit Java Library

Now that the PSPDFKit Java Library is added, you can use the SDK in your application. You will have to call the initialize method prior to calling any other PSPDFKit method.

Here’s a small example showing how to import Instant JSON and save the document:

Copy
1
2
3
4
5
6
7
8
public void exampleOperation() throws NativePSPDFKitLibraryLoadException {
    PSPDFKit.initialize("YOUR_LICENSE_KEY_GOES_HERE");
    File documentFile = new File("Assets/default.pdf");
    PdfDocument document = new PdfDocument(new FileDataProvider(documentFile));

    File jsonFile = new File("Assets/instant.json");
    document.importJson(new FileDataProvider(jsonFile));
}

To your retrieve the license key :

  • Log in to the PSPDFKit Customer Portal using the credentials you received when purchasing PSPDFKit. You will see the list of all your purchased licenses.
  • Locate your license (e.g. PSPDFKit Java Library)
  • Click the License Key button next to it. A dialog will open showing you a code snippet with your license key.

For more examples on how to use the SDK, please refer to both the Catalog example in PSPDFKit-Java-binary-*.*.*.zip and the API documentation.