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 based on your device 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.

  • For 32-bit binary packages and slimmer binaries (including java libraries), visit the C++ docs for Server SDK.
  • 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 Windows PDFNetJava.zip file.
  2. Extract the PDFNetJava.zip file to the following location: C:\Users\YourName\ 
    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 HelloWorld.
  4. Right-click on the HelloWorld folder, select New File and name it HelloWorld.java.

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

  1. Copy the following code and paste it into the HelloWorld.java file to create a blank PDF page:

Java

1import java.io.File;
2import java.io.IOException;
3// These are the most important packages to import
4// for basic document manipulation.
5import com.pdftron.common.PDFNetException;
6import com.pdftron.pdf.*;
7import com.pdftron.sdf.SDFDoc;
8import java.io.*;
9public class HelloWorld
10{
11 // Just a simple setup for the application
12 public static void main(String[] args)
13 {
14 // PDFNet must always be initialized before any Apryse
15 // classes and methods can be used
16 PDFNet.initialize("YOUR_APRYSE_LICENSE_KEY");
17 System.out.println("Hello World!");
18 // Most Apryse operations are required to be wrapped in
19 // a try-catch block for PDFNetException, or in a method/class that
20 // throws PDFNetException
21 try {
22 // Creates a new PDFDoc object
23 PDFDoc doc = new PDFDoc();
24 // Creating a new page and adding it
25 // to document's sequence of pages
26 Page page1 = doc.pageCreate();
27 doc.pagePushBack(page1);
28 // Files can be saved with various options
29 // Linearized files are the most effective
30 // for opening and viewing quickly on various platforms
31 doc.save(("linearized_ouput.pdf"), SDFDoc.SaveMode.LINEARIZED, null);
32 doc.close();
33 } catch (PDFNetException e) {
34 System.out.println(e);
35 e.getStackTrace();
36 }
37 PDFNet.terminate();
38 }
39}

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

3. Run your project

  1. Open Windows PowerShell and navigate to: C:\Users\YourName\PDFNetJava\Samples\HelloWorld.
  2. Type the following command line and press Enter. This compiles the HelloWorld.java with the PDFNet.jar file added to the Java classpath:

Shell

1javac -cp ".;..\..\Lib\PDFNet.jar" HelloWorld.java

3. Type the following command to launch the application and load the Apryse Server SDK Java and native library dependencies:

sh

1java --% -Djava.library.path=..\..\Lib -cp ".;..\..\Lib\PDFNet.jar" HelloWorld

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.

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

5. Return to Visual Studio Code. In your Samples > HelloWorld folder, you will see the linearized_output.pdf file you created by integrating the Apryse Server SDK!

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

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