Get Started with the Apryse Server SDK Java PDF Library Integration

This article provides steps to create a simple Java project that uses the Apryse SDK and the PDFNet library to programmatically generate a blank PDF document. With these steps, you can learn how to set up your environment, import the required libraries, and run a script that produces a valid PDF file—all without manual intervention.

To get started, choose your preferred platform from the tabs below.

Prerequisites

Before you start:

  • Install Visual Studio Code (or your preferred application) to write, edit, and debug source code.
  • If you’re using VS Code, install the “Extension Pack for Java” and the “vscode-pdf” extensions that are available in the “Extensions: Marketplace” tab within VS Code. This will provide you with a full-featured Java development environment by bundling the essential tools.
  • Install the latest Java Development Kit (JDK) v25 (LTS) for your platform/processor.

You must set the JAVA_HOME environment variable to the installation directory for your JDK to allow other tools to find it, otherwise, you will receive an error while running the samples.

  • Get your Apryse trial key.

License Key

Apryse collects some data regarding your usage of the SDK for product improvement.

If you wish to continue without data collection, contact us and we will email you a no-tracking trial key for you to get started.

Run Apryse SDK in production.

A commercial license key is required for use in a production environment. Contact sales by filling out our licensing form if you want to purchase a commercial license key.

Keep your commercial license key confidential.

License keys are uniquely generated and strictly confidential. Don't publish or store them in any public location, including public GitHub repositories.

1. Create a new PDFNet Java project

This section provides steps to create a simple Java project.

  1. Download the Apryse Java PDF library for Linux PDFNetJava.zip file.
  2. Extract the PDFNetJava.zip file to the following location: /Home/YourName/PDFNetJava/Samples/
    Replace YourName with your user name.
  3. In Visual Studio Code, from the Explorer pane, click on the Samples section, select the New Folder icon and enter myApp.
  4. Right-click on the myApp folder, select New File and name it JAVA.

2. Initialize and integrate the Apryse Server SDK into your application

  1. From the myApp folder, in the new file you just created, copy the following code and paste it into the myApp.java file to create a blank PDF page:

Java

1import java.io.File;
2import java.io.IOException;
3import com.pdftron.common.PDFNetException;
4import com.pdftron.pdf.*;
5import com.pdftron.sdf.SDFDoc;
6import com.pdftron.sdf.ObjSet;
7import com.pdftron.sdf.Obj;
8public class myApp
9{
10 public static void main(String[] args)
11 {
12 PDFNet.initialize("YOUR_APRYSE_LICENSE_KEY"); // PDFNet must be initialized before accessing any Apryse API
13 try
14 {
15 PDFDoc doc = new PDFDoc();
16 Page page = doc.pageCreate(); // Start a new page
17 doc.pagePushBack(page); // Add the page to the document
18 doc.save("output.pdf", SDFDoc.SaveMode.LINEARIZED, null); // Save the document as a linearized PDF
19 }
20 catch(PDFNetException e)
21 {
22 e.printStackTrace();
23 System.out.println(e);
24 }
25 System.out.println("Hello World!");
26 }
27}

2. Scroll down to the line containing PDFNet.initialize(“YOUR_PDFTRON_LICENSE_KEY”); and replace the words in quotes with the copy of your trial license key. Save your changes.

3. Run your project

  1. Right-click on the myApp.java file and select Open in Integrated Terminal.
  2. In the terminal, enter the following and press Enter to compile your application using the PDFNet library:

sh

1javac -cp .:../../../Lib/PDFNet.jar myApp.java

Then enter the following and press Enter to run the project:

sh

1java -Djava.library.path=../../../Lib -classpath .:../../../Lib/PDFNet.jar myApp

Keep in mind the following about the code above:

  • The system logs a startup message.
  • The program imports the Java SDK.
  • The script defines an async main function that builds the PDF.
  • The PDFNet engine runs with cleanup and license initialization.
  • The program logs any errors.
  • The script releases PDFNet resources and shuts down the engine.

3. In the terminal, type exit and press Enter.

4. In your Samples > myApp folder, you will see the output.pdf file you created by integrating the Apryse Server SDK!

5. You have successfully added the Apryse Server SDK to your Java project.

Additional ways to integrate.

If you prefer to use Maven or Gradle, choose from the following tabs:

1. Add the PDFNet Maven repository in your top-level pom.xml.

XML

1<repositories>
2 <repository>
3 <id>pdftron</id>
4 <name>PDFNet Maven</name>
5 <url>https://pdftron.com/maven/release</url>
6 </repository>
7</repositories>

2. Add the PDFNet Maven dependency in your pom.xml.

XML

1<dependencies>
2 <dependency>
3 <groupId>com.pdftron</groupId>
4 <artifactId>PDFNet</artifactId>
5 <version>11.1.0</version>
6 </dependency>
7</dependencies>

Integrate into your application

  1. Add PDFNet Maven repository and dependency in your pom.xml.
  2. In your src\main\java\your\java\folder\, add the following code to your java files. We use src\main\java\com\mycompany\app\App.java as an example:

Java

1package com.mycompany.app;
2import com.pdftron.pdf.*;
3public class App
4{
5 public static void main(String[] args)
6 {
7 PDFNet.initialize("YOUR_APRYSE_LICENSE_KEY");
8 try {
9 // YOUR CODE GOES HERE
10 } catch (Exception e) {
11 }
12 PDFNet.terminate();
13 }
14}

To test your code, you can navigate to the root of your project and run the following commands:

Bash

1mvn compile
2mvn exec:java -Dexec.mainClass=com.mycompany.app.App

If the program runs successfully, you should see no error in the terminal.

We have demonstrated how to integrate Apryse's Java SDK into your Maven project. If your have any questions, please don't hesitate to contact us!

Next Steps

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales