> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/core/get-started/languages/java.md).

# Build a Java PDF library app with Apryse Server SDK

Learn how to build a simple Java PDF application using the Apryse Java PDF library and Server SDK to generate PDFs programmatically.

This guide shows how to build a simple Java PDF application that uses the [Apryse Server SDK](https://docs.apryse.com/try-now?tab-cfc13cf95cb8=server+%2F+desktop+sdk) and PDFNet library to generate a PDF programmatically. You’ll set up a minimal project, install the SDK, and add the required code to create a blank PDF document. This example provides a practical foundation for building more advanced document‑generation workflows.

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

{% tabs %}
{% tab title="Windows" %}

## Prerequisites

Before you start:

* Install [Visual Studio Code](https://code.visualstudio.com/Download) or another code editor to develop and debug your code.
* Install the [Extension Pack for Java](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-pack) and the [vscode-pdf](https://marketplace.visualstudio.com/items?itemName=tomoki1207.pdf) extension from the [Extensions Marketplace](https://code.visualstudio.com/docs/configure/extensions/extension-marketplace) if using VS Code.
* Install [Java Development Kit](https://www.oracle.com/java/technologies/downloads/) (JDK) 25 (LTS) for your platform.

{% hint style="info" %}
Set the [JAVA\_HOME environment variable](https://www.youtube.com/watch?v=DNQ9uR11X2M) to your JDK installation directory so your system can locate Java. If it's not set correctly, you may encounter errors when running your project.
{% endhint %}

* For 32-bit binary packages and slimmer binaries (including Java libraries), visit the [C++ docs for Server SDK](/core/get-started/languages/cpp.md).
* Install Apache Maven or Gradle if you plan to use a build tool to manage dependencies and run your project.
* Get your Apryse trial key.

{% @apryse-license-key/apryse-license-key platform="SERVER" variant="full" %}

{% hint style="info" %}
**Run Apryse SDK in production**

A commercial license key is required for use in a production environment. [Contact sales](https://apryse.com/form/contact-sales) to purchase a commercial license key.
{% endhint %}

{% hint style="warning" %}
**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.
{% endhint %}

## 1. Set up your project

This section uses a manual setup, where you create a simple Java project and add the Apryse Server SDK using the JAR files from the downloaded package. This approach is useful for quick testing and understanding how the SDK works. If you’re using a build tool such as Maven or Gradle in an existing Java project, skip to the next section.

1. Download and unzip the [PDFNetJava.zip](https://downloads.apryse.com/downloads/PDFNetJava.zip) file to a location of your choice.
2. Open the extracted `/PDFNetJava/Samples` folder in Visual Studio Code.
3. In the `Samples` directory, create a `MyApp/java` folder structure.
4. In the `java` folder, create a `MyApp.java` file. Your project should now include a similar structure:

{% code lineNumbers="true" %}

```
SAMPLES/
├── MyApp/              
│   └── java/
│       └── MyApp.java
├── OCRTest/
├── OfficeTemplateTest/
└── ... (other sample folders)
```

{% endcode %}

## 2. Add the Apryse SDK

Next, you'll integrate the Apryse Server SDK into your Java application and add the code needed to generate a PDF. You can use a manual setup by adding the SDK JAR files directly, or use Maven or Gradle to include the SDK as a dependency.

{% tabs %}
{% tab title="Manual" %}

1. Open the `MyApp.java` file in Visual Studio Code or your preferred code editor.
2. Add the following code to the `MyApp.java` file, update your license key, and save your changes:

<pre class="language-java" data-line-numbers><code class="lang-java">import java.io.File;
import java.io.IOException;

// Import exception handling
import com.pdftron.common.PDFNetException;
// Import core PDF functionality
import com.pdftron.pdf.*;
// Import low-level SDF (structured document format) classes
import com.pdftron.sdf.SDFDoc;

public class MyApp
{ 
  public static void main(String[] args)
  {
    // Initialize PDFNet library
    // Replace with your license key
    PDFNet.initialize("<code class="expression">visitor.claims.serverKey || "YOUR_LICENSE_KEY"</code>");
    try
    {
      // Create new PDF and add blank page
      PDFDoc doc = new PDFDoc();
      Page page = doc.pageCreate();
      doc.pagePushBack(page);

      // Save as a linearized (web-optimized) PDF
      doc.save("output.pdf", SDFDoc.SaveMode.LINEARIZED, null);
     }
     // Handle PDFTron-specific exceptions
     catch(PDFNetException e)
     {
       e.printStackTrace();
       System.out.println(e);
     }

     // Print simple console output to confirm program ran
     System.out.println("Blank PDF created successfully: output.pdf");
  }
}
</code></pre>

{% hint style="info" %}
**Info**

If you're signed in with an Apryse account, your license key is automatically prepopulated in all code snippets.
{% endhint %}

With this code, you can:

* Import the required Apryse `PDFNet` namespaces.
* Define a `main` method to serve as the starting point for execution.
* Initialize the Apryse SDK with a license key.
* Create a new PDF document, add a blank page, and save it as a linearized PDF.
* Log errors to the console.
* Output a simple message to confirm the program ran successfully.
  {% endtab %}

{% tab title="Maven" %}

1. In Visual Studio Code, open your project’s `pom.xml` file.
2. Add the `PDFNet Maven` repository and dependency in the `pom.xml` file and save your changes:

{% code title="pom.xml" lineNumbers="true" %}

```xml
<project>
  . . .
  <repositories>
    <repository>
      <id>pdftron</id>
      <name>PDFNet Maven</name>
      <url>https://pdftron.com/maven/release</url>
    </repository>
  </repositories>
  
  <dependencies>
    <dependency>
      <groupId>com.pdftron</groupId>
      <artifactId>PDFNet</artifactId>
      <!-- Check the Apryse release notes for the latest version number -->
      <version>12.0.0</version>
    </dependency>
  </dependencies>
  . . .
</project>
```

{% endcode %}

{% hint style="info" %}
**Info**

The [maven-metadata.xml](https://pdfnet-maven.s3.us-west-2.amazonaws.com/release/com/pdftron/PDFNet/maven-metadata.xml) endpoint lists all published versions of the `com.pdftron:PDFNet` artifact, along with the latest and release versions. This is useful for determining which version to specify in your `pom.xml` dependency.
{% endhint %}

3. Add the following code to a Java file in `src/main/java/<your_package>/`, such as `src/main/java/com/example/app/Main.java`, update your license key, and save your changes:

<pre class="language-java" data-line-numbers><code class="lang-java">package com.example.app;

// Import exception handling
import com.pdftron.common.PDFNetException;
// Import core PDF functionality
import com.pdftron.pdf.*;
// Import low-level SDF (structured document format) classes
import com.pdftron.sdf.SDFDoc;

public class Main
{
  public static void main(String[] args)
  {
    // Initialize PDFNet library
    // Replace with your license key
    PDFNet.initialize("<code class="expression">visitor.claims.serverKey || "YOUR_LICENSE_KEY"</code>");
    try
    {
      // Create new PDF and add blank page
      PDFDoc doc = new PDFDoc();
      Page page = doc.pageCreate();
      doc.pagePushBack(page);
        
      // Save as a linearized (web-optimized) PDF
      doc.save("output.pdf", SDFDoc.SaveMode.LINEARIZED, null);
    }
    // Handle PDFTron-specific exceptions
    catch(PDFNetException e)
    {
      e.printStackTrace();
      System.out.println(e);
    }

    // Print simple console output to confirm program ran
    System.out.println("Blank PDF created successfully: output.pdf");
  }
}
</code></pre>

{% hint style="info" %}
**Info**

If you're signed in with an Apryse account, your license key is automatically prepopulated in all code snippets.
{% endhint %}

With this code, you can:

* Import the required Apryse `PDFNet` namespaces.
* Define a `main` method to serve as the starting point for execution.
* Initialize the Apryse SDK with a license key.
* Create a new PDF document, add a blank page, and save it as a linearized PDF.
* Log errors to the console.
* Output a simple message to confirm the program ran successfully.
  {% endtab %}

{% tab title="Gradle" %}

1. In Visual Studio Code, open your top-level `build.gradle` file.
2. Add the Apryse Maven repository, dependency, and application configuration to your `build.gradle` file and save your changes:

{% code title="build.gradle" lineNumbers="true" %}

```groovy
plugins {
  id 'java'
  id 'application'
}

repositories {
  mavenCentral()
  maven {
    url "https://pdftron.com/maven/release/"
  }
}

dependencies {
  // Check the Apryse release notes for the latest version number
  implementation "com.pdftron:PDFNet:12.0.0"
}

application {
  mainClass = 'com.example.app.Main'
}
```

{% endcode %}

{% hint style="info" %}
**Info**

If the `plugins`, `repositories`, or `dependencies` blocks already exist, add the new entries to them instead of creating duplicate sections.
{% endhint %}

{% hint style="info" %}
**Info**

The [maven-metadata.xml](https://pdfnet-maven.s3.us-west-2.amazonaws.com/release/com/pdftron/PDFNet/maven-metadata.xml) endpoint lists all published versions of the `com.pdftron:PDFNet` artifact, along with the latest and release versions. This is useful for determining which version to specify in your `pom.xml` dependency.
{% endhint %}

3. Add the following code to a Java file in `src/main/java/<your-package>/`, such as `src/main/java/com/example/app/Main.java`, update your license key, and save your changes:

<pre class="language-java" data-line-numbers><code class="lang-java">package com.example.app;

// Import exception handling
import com.pdftron.common.PDFNetException;
// Import core PDF functionality
import com.pdftron.pdf.*;
// Import low-level SDF (structured document format) classes
import com.pdftron.sdf.SDFDoc;

public class Main
{
  public static void main(String[] args)
  {
    // Initialize PDFNet library
    // Replace with your license key
    PDFNet.initialize("<code class="expression">visitor.claims.serverKey || "YOUR_LICENSE_KEY"</code>");
    try
    {
      // Create new PDF and add blank page
      PDFDoc doc = new PDFDoc();
      Page page = doc.pageCreate();
      doc.pagePushBack(page);
      
	  // Save as a linearized (web-optimized) PDF
      doc.save("output.pdf", SDFDoc.SaveMode.LINEARIZED, null);
    }
    // Handle PDFTron-specific exceptions
    catch(PDFNetException e)
    {
      e.printStackTrace();
      System.out.println(e);
    }

    // Print simple console output to confirm program ran
    System.out.println("Blank PDF created successfully: output.pdf");
  }
}
</code></pre>

{% hint style="info" %}
**Info**

If you're signed in with an Apryse account, your license key is automatically prepopulated in all code snippets.
{% endhint %}

With this code, you can:

* Import the required Apryse `PDFNet` namespaces.
* Define a `main` method to serve as the starting point for execution.
* Initialize the Apryse SDK with a license key.
* Create a new PDF document, add a blank page, and save it as a linearized PDF.
* Log errors to the console.
* Output a simple message to confirm the program ran successfully.
  {% endtab %}
  {% endtabs %}

## 3. Verify your output

Finally, build and run your Java application to confirm that the Apryse Server SDK is working correctly. After the application runs successfully, it will generate a blank PDF file locally. Instructions are provided for manual, Maven, and Gradle-based integrations.

{% tabs %}
{% tab title="Manual" %}

1. Navigate to the `PDFNetJava/Samples/MyApp/java` directory.
2. In the terminal, run this command to compile `MyApp.java` with the `PDFNet.jar` file added to the Java classpath:

{% code lineNumbers="true" %}

```powershell
javac -cp ".;..\..\..\Lib\PDFNet.jar" MyApp.java 
```

{% endcode %}

3. Launch the application and load the Apryse Server SDK Java and native library dependencies:

{% code lineNumbers="true" %}

```powershell
java --% -Djava.library.path=..\..\..\Lib -cp ".;..\..\..\Lib\PDFNet.jar" MyApp
```

{% endcode %}

A successful output looks similar to:

{% code lineNumbers="true" %}

```powershell
PDFNet is running in demo mode.
PackageV2: base
Blank PDF created successfully: output.pdf
```

{% endcode %}

4. Verify a blank `output.pdf` file was generated in the `/PDFNetJava/Samples/MyApp/java` directory. The folder structure looks similar to:

{% code lineNumbers="true" %}

```
PDFNetJava/
├── Doc/
├── Samples/
│   ├── MyApp/
│   │   └── java/
│   │       ├── output.pdf
│   │       ├── MyApp.class
│   │       └── MyApp.java
│   ├── HandwritingOCRTest/
│   └── ... (other sample folders)
```

{% endcode %}
{% endtab %}

{% tab title="Maven" %}

1. From the root of your Maven project, compile the application and download all required dependencies:

{% code lineNumbers="true" %}

```powershell
mvn compile
```

{% endcode %}

2. After the project compiles successfully, start the application and generate the PDF:

{% code lineNumbers="true" %}

```powershell
mvn exec:java "-Dexec.mainClass=com.example.app.Main"
```

{% endcode %}

3. Check the terminal output to ensure a successful build. A successful output looks similar to:

{% code lineNumbers="true" %}

```powershell
PDFNet is running in demo mode.
PackageV2: base
Blank PDF created successfully: output.pdf
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.903 s
[INFO] Finished at: 2026-06-24T12:11:21-04:00
[INFO] ------------------------------------------------------------------------
```

{% endcode %}

4. Verify that the Server SDK generated a blank `output.pdf` file in the root of your Java project.
   {% endtab %}

{% tab title="Gradle" %}

1. From the root of your Gradle project, run this command to build and start the application:

{% code lineNumbers="true" %}

```powershell
.\gradlew run
```

{% endcode %}

2. Check the terminal output to ensure a successful build. A successful output looks similar to:

{% code lineNumbers="true" %}

```powershell
PDFNet is running in demo mode.
PackageV2: base
Blank PDF created successfully: output.pdf

BUILD SUCCESSFUL in 3s
```

{% endcode %}

3. Verify that the Server SDK generated a blank `output.pdf` file in the root of your Java project.
   {% endtab %}
   {% endtabs %}
   {% endtab %}

{% tab title="Linux" %}

## Prerequisites

Before you start:

* Install [Visual Studio Code](https://code.visualstudio.com/Download) or another code editor to develop and debug your code.
* Install the [Extension Pack for Java](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-pack) and the [vscode-pdf](https://marketplace.visualstudio.com/items?itemName=tomoki1207.pdf) extension from the [Extensions Marketplace](https://code.visualstudio.com/docs/configure/extensions/extension-marketplace) if using VS Code.
* Install [Java Development Kit](https://www.oracle.com/java/technologies/downloads/) (JDK) 25 (LTS) for your platform.

{% hint style="info" %}
Set the [JAVA\_HOME environment variable](https://www.youtube.com/watch?v=DNQ9uR11X2M) to your JDK installation directory so your system can locate Java. If it's not set correctly, you may encounter errors when running your project.
{% endhint %}

* Install Apache Maven or Gradle if you plan to use a build tool to manage dependencies and run your project.
* Get your Apryse trial key.

{% @apryse-license-key/apryse-license-key platform="SERVER" variant="full" %}

{% hint style="info" %}
**Run Apryse SDK in production**

A commercial license key is required for use in a production environment. [Contact sales](https://apryse.com/form/contact-sales) to purchase a commercial license key.
{% endhint %}

{% hint style="warning" %}
**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.
{% endhint %}

## 1. Set up your project

This section uses a manual setup, where you create a simple Java project and add the Apryse Server SDK using the JAR files from the downloaded package. This approach is useful for quick testing and understanding how the SDK works. If you’re using a build tool such as Maven or Gradle in an existing Java project, skip to the next section.

1. Download and unzip the [PDFNetJava.zip](https://downloads.apryse.com/downloads/PDFNetJava.zip) file to a location of your choice.
2. Open the extracted `/PDFNetJava/Samples` folder in Visual Studio Code.
3. In the `Samples` directory, create a `MyApp/java` folder structure.
4. In the `java` folder, create a `MyApp.java` file. Your project should now include a similar structure:

{% code lineNumbers="true" %}

```
SAMPLES/
├── MyApp/              
│   └── java/
│       └── MyApp.java
├── OCRTest/
├── OfficeTemplateTest/
└── ... (other sample folders)
```

{% endcode %}

## 2. Add the Apryse SDK

Next, you'll integrate the Apryse Server SDK into your Java application and add the code needed to generate a PDF. You can use a manual setup by adding the SDK JAR files directly, or use Maven or Gradle to include the SDK as a dependency.

{% tabs %}
{% tab title="Manual" %}

1. Open the `MyApp.java` file in Visual Studio Code or your preferred code editor.
2. Add the following code to the `MyApp.java` file, update your license key, and save your changes:

<pre class="language-java" data-line-numbers><code class="lang-java">import java.io.File;
import java.io.IOException;

// Import exception handling
import com.pdftron.common.PDFNetException;
// Import core PDF functionality
import com.pdftron.pdf.*;
// Import low-level SDF (structured document format) classes
import com.pdftron.sdf.SDFDoc;

public class MyApp
{ 
  public static void main(String[] args)
  {
    // Initialize PDFNet library
    // Replace with your license key
    PDFNet.initialize("<code class="expression">visitor.claims.serverKey || "YOUR_LICENSE_KEY"</code>");
    try
    {
      // Create new PDF and add blank page
      PDFDoc doc = new PDFDoc();
      Page page = doc.pageCreate();
      doc.pagePushBack(page);

      // Save as a linearized (web-optimized) PDF
      doc.save("output.pdf", SDFDoc.SaveMode.LINEARIZED, null);
     }
     // Handle PDFTron-specific exceptions
     catch(PDFNetException e)
     {
       e.printStackTrace();
       System.out.println(e);
     }

     // Print simple console output to confirm program ran
     System.out.println("Blank PDF created successfully: output.pdf");
  }
}
</code></pre>

{% hint style="info" %}
**Info**

If you're signed in with an Apryse account, your license key is automatically prepopulated in all code snippets.
{% endhint %}

With this code, you can:

* Import the required Apryse `PDFNet` namespaces.
* Define a `main` method to serve as the starting point for execution.
* Initialize the Apryse SDK with a license key.
* Create a new PDF document, add a blank page, and save it as a linearized PDF.
* Log errors to the console.
* Output a simple message to confirm the program ran successfully.
  {% endtab %}

{% tab title="Maven" %}

1. In Visual Studio Code, open your project’s `pom.xml` file.
2. Add the `PDFNet Maven` repository and dependency in the `pom.xml` file and save:

{% code title="pom.xml" lineNumbers="true" %}

```xml
<project>
  . . .
  <repositories>
    <repository>
      <id>pdftron</id>
      <name>PDFNet Maven</name>
      <url>https://pdftron.com/maven/release</url>
    </repository>
  </repositories>
  
  <dependencies>
    <dependency>
      <groupId>com.pdftron</groupId>
      <artifactId>PDFNet</artifactId>
      <!-- Check the Apryse release notes for the latest version number -->
      <version>12.0.0</version>
    </dependency>
  </dependencies>
  . . .
</project>
```

{% endcode %}

{% hint style="info" %}
**Info**

The [maven-metadata.xml](https://pdfnet-maven.s3.us-west-2.amazonaws.com/release/com/pdftron/PDFNet/maven-metadata.xml) endpoint lists all published versions of the `com.pdftron:PDFNet` artifact, along with the latest and release versions. This is useful for determining which version to specify in your `pom.xml` dependency.
{% endhint %}

3. Add the following code to a Java file in `src/main/java/<your_package>/`, such as `src/main/java/com/example/app/Main.java`, update your license key, and save your changes:

<pre class="language-java" data-line-numbers><code class="lang-java">package com.example.app;

// Import exception handling
import com.pdftron.common.PDFNetException;
// Import core PDF functionality
import com.pdftron.pdf.*;
// Import low-level SDF (structured document format) classes
import com.pdftron.sdf.SDFDoc;

public class Main
{
  public static void main(String[] args)
  {
    // Initialize PDFNet library
    // Replace with your license key
    PDFNet.initialize("<code class="expression">visitor.claims.serverKey || "YOUR_LICENSE_KEY"</code>");
    try
    {
      // Create new PDF and add blank page
      PDFDoc doc = new PDFDoc();
      Page page = doc.pageCreate();
      doc.pagePushBack(page);
        
      // Save as a linearized (web-optimized) PDF
      doc.save("output.pdf", SDFDoc.SaveMode.LINEARIZED, null);
    }
    // Handle PDFTron-specific exceptions
    catch(PDFNetException e)
    {
      e.printStackTrace();
      System.out.println(e);
    }

    // Print simple console output to confirm program ran
    System.out.println("Blank PDF created successfully: output.pdf");
  }
}
</code></pre>

{% hint style="info" %}
**Info**

If you're signed in with an Apryse account, your license key is automatically prepopulated in all code snippets.
{% endhint %}

With this code, you can:

* Import the required Apryse `PDFNet` namespaces.
* Define a `main` method to serve as the starting point for execution.
* Initialize the Apryse SDK with a license key.
* Create a new PDF document, add a blank page, and save it as a linearized PDF.
* Log errors to the console.
* Output a simple message to confirm the program ran successfully.
  {% endtab %}

{% tab title="Gradle" %}

1. In Visual Studio Code, open your top-level `build.gradle` file.
2. Add the `PDFNet Maven` repository and dependency to your `build.gradle` file and save:

{% code title="build.gradle" lineNumbers="true" %}

```groovy
plugins {
  id 'java'
  id 'application'
}

repositories {
  mavenCentral()
  maven {
    url "https://pdftron.com/maven/release/"
  }
}

dependencies {
  // Check the Apryse release notes for the latest version number
  implementation "com.pdftron:PDFNet:12.0.0"
}

application {
  mainClass = 'com.example.app.Main'
}
```

{% endcode %}

{% hint style="info" %}
**Info**

If the `plugins`, `repositories`, or `dependencies` blocks already exist, add the new entries to them instead of creating duplicate sections.
{% endhint %}

{% hint style="info" %}
**Info**

The [maven-metadata.xml](https://pdfnet-maven.s3.us-west-2.amazonaws.com/release/com/pdftron/PDFNet/maven-metadata.xml) endpoint lists all published versions of the `com.pdftron:PDFNet` artifact, along with the latest and release versions. This is useful for determining which version to specify in your `pom.xml` dependency.
{% endhint %}

3. Add the following code to a Java file in `src/main/java/<your-package>/`, such as `src/main/java/com/example/app/Main.java`, update your license key, and save your changes:

<pre class="language-java" data-line-numbers><code class="lang-java">package com.example.app;

// Import exception handling
import com.pdftron.common.PDFNetException;
// Import core PDF functionality
import com.pdftron.pdf.*;
// Import low-level SDF (structured document format) classes
import com.pdftron.sdf.SDFDoc;

public class Main
{
  public static void main(String[] args)
  {
    // Initialize PDFNet library
    // Replace with your license key
    PDFNet.initialize("<code class="expression">visitor.claims.serverKey || "YOUR_LICENSE_KEY"</code>");
    try
    {
      // Create new PDF and add blank page
      PDFDoc doc = new PDFDoc();
      Page page = doc.pageCreate();
      doc.pagePushBack(page);
      
	  // Save as a linearized (web-optimized) PDF
      doc.save("output.pdf", SDFDoc.SaveMode.LINEARIZED, null);
    }
    // Handle PDFTron-specific exceptions
    catch(PDFNetException e)
    {
      e.printStackTrace();
      System.out.println(e);
    }

    // Print simple console output to confirm program ran
    System.out.println("Blank PDF created successfully: output.pdf");
  }
}
</code></pre>

{% hint style="info" %}
**Info**

If you're signed in with an Apryse account, your license key is automatically prepopulated in all code snippets.
{% endhint %}

With this code, you can:

* Import the required Apryse `PDFNet` namespaces.
* Define a `main` method to serve as the starting point for execution.
* Initialize the Apryse SDK with a license key.
* Create a new PDF document, add a blank page, and save it as a linearized PDF.
* Log errors to the console.
* Output a simple message to confirm the program ran successfully.
  {% endtab %}
  {% endtabs %}

## 3. Verify your output

Finally, build and run your Java application to confirm that the Apryse Server SDK is working correctly. After the application runs successfully, it will generate a blank PDF file locally. Instructions are provided for manual, Maven, and Gradle-based integrations.

{% tabs %}
{% tab title="Manual" %}

1. Navigate to the `PDFNetJava/Samples/MyApp/java` directory.
2. In the terminal, run this command to compile `MyApp.java` with the `PDFNet.jar` file added to the Java classpath:

{% code lineNumbers="true" %}

```bash
javac -cp .:../../../Lib/PDFNet.jar MyApp.java
```

{% endcode %}

3. Launch the application and load the Apryse Server SDK Java and native library dependencies:

{% code lineNumbers="true" %}

```bash
java -Djava.library.path=../../../Lib -classpath .:../../../Lib/PDFNet.jar MyApp 
```

{% endcode %}

A successful output looks similar to:

{% code lineNumbers="true" %}

```bash
PDFNet is running in demo mode.
PackageV2: base
Blank PDF created successfully: output.pdf
```

{% endcode %}

4. Verify a blank `output.pdf` file was generated in the `/PDFNetJava/Samples/MyApp/java` directory. The folder structure looks similar to:

{% code lineNumbers="true" %}

```
PDFNetJava/
├── Doc/
├── Samples/
│   ├── MyApp/
│   │   └── java/
│   │       ├── output.pdf
│   │       ├── MyApp.class
│   │       └── MyApp.java
│   ├── HandwritingOCRTest/
│   └── ... (other sample folders)
```

{% endcode %}
{% endtab %}

{% tab title="Maven" %}

1. From the root of your Maven project, compile the application and download all required dependencies:

{% code lineNumbers="true" %}

```bash
mvn compile
```

{% endcode %}

2. After the project compiles successfully, start the application and generate the PDF:

{% code lineNumbers="true" %}

```bash
mvn exec:java -Dexec.mainClass=com.example.app.Main
```

{% endcode %}

3. Check the terminal output to ensure a successful build. A successful output looks similar to:

{% code lineNumbers="true" %}

```bash
PDFNet is running in demo mode.
Package: base
Blank PDF created successfully: output.pdf
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.903 s
[INFO] Finished at: 2026-06-24T12:11:21-04:00
[INFO] ------------------------------------------------------------------------
```

{% endcode %}

4. Verify that the Server SDK generated a blank `output.pdf` file in the root of your Java project.
   {% endtab %}

{% tab title="Gradle" %}

1. From the root of your Gradle project, run this command to build and start the application:

{% code lineNumbers="true" %}

```bash
./gradlew run
```

{% endcode %}

2. Check the terminal output to ensure a successful build. A successful output looks similar to:

{% code lineNumbers="true" %}

```bash
PDFNet is running in demo mode.
Package: base
Blank PDF created successfully: output.pdf

BUILD SUCCESSFUL in 3s
```

{% endcode %}

3. Verify that the Server SDK generated a blank `output.pdf` file in the root of your Java project.
   {% endtab %}
   {% endtabs %}

##

{% endtab %}

{% tab title="macOS" %}

## Prerequisites

Before you start:

* Install [Visual Studio Code](https://code.visualstudio.com/Download) or another code editor to develop and debug your code.
* Install the [Extension Pack for Java](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-pack) and the [vscode-pdf](https://marketplace.visualstudio.com/items?itemName=tomoki1207.pdf) extension from the [Extensions Marketplace](https://code.visualstudio.com/docs/configure/extensions/extension-marketplace) if using VS Code.
* Install [Java Development Kit](https://www.oracle.com/java/technologies/downloads/) (JDK) 25 (LTS) for your platform.

{% hint style="info" %}
Set the [JAVA\_HOME environment variable](https://www.youtube.com/watch?v=DNQ9uR11X2M) to your JDK installation directory so your system can locate Java. If it's not set correctly, you may encounter errors when running your project.
{% endhint %}

* Install Apache Maven or Gradle if you plan to use a build tool to manage dependencies and run your project.
* Get your Apryse trial key.

{% @apryse-license-key/apryse-license-key platform="SERVER" variant="full" %}

{% hint style="info" %}
**Run Apryse SDK in production**

A commercial license key is required for use in a production environment. [Contact sales](https://apryse.com/form/contact-sales) to purchase a commercial license key.
{% endhint %}

## 1. Set up your project

This section uses a manual setup, where you create a simple Java project and add the Apryse Server SDK using the JAR files from the downloaded package. This approach is useful for quick testing and understanding how the SDK works. If you’re using a build tool such as Maven or Gradle in an existing Java project, skip to the next section.

1. Download and unzip the [PDFNetJava.zip](https://downloads.apryse.com/downloads/PDFNetJava.zip) file to a location of your choice.
2. Open the extracted `/PDFNetJava/Samples` folder in Visual Studio Code.
3. In the `Samples` directory, create a `MyApp/java` folder structure.
4. In the `java` folder, create a `MyApp.java` file. Your project should now include a similar structure:

{% code lineNumbers="true" %}

```
SAMPLES/
├── MyApp/              
│   └── java/
│       └── MyApp.java
├── OCRTest/
├── OfficeTemplateTest/
└── ... (other sample folders)
```

{% endcode %}

## 2. Add the Apryse SDK

Next, you'll integrate the Apryse Server SDK into your Java application and add the code needed to generate a PDF. You can use a manual setup by adding the SDK JAR files directly, or use Maven or Gradle to include the SDK as a dependency.

{% tabs %}
{% tab title="Manual" %}

1. Open the `MyApp.java` file in Visual Studio Code or your preferred code editor.
2. Add the following code to the `MyApp.java` file, update your license key, and save your changes:

<pre class="language-java" data-line-numbers><code class="lang-java">import java.io.File;
import java.io.IOException;

// Import exception handling
import com.pdftron.common.PDFNetException;
// Import core PDF functionality
import com.pdftron.pdf.*;
// Import low-level SDF (structured document format) classes
import com.pdftron.sdf.SDFDoc;

public class MyApp
{ 
  public static void main(String[] args)
  {
    // Initialize PDFNet library
    // Replace with your license key
    PDFNet.initialize("<code class="expression">visitor.claims.serverKey || "YOUR_LICENSE_KEY"</code>");
    try
    {
      // Create new PDF and add blank page
      PDFDoc doc = new PDFDoc();
      Page page = doc.pageCreate();
      doc.pagePushBack(page);

      // Save as a linearized (web-optimized) PDF
      doc.save("output.pdf", SDFDoc.SaveMode.LINEARIZED, null);
     }
     // Handle PDFTron-specific exceptions
     catch(PDFNetException e)
     {
       e.printStackTrace();
       System.out.println(e);
     }

     // Print simple console output to confirm program ran
     System.out.println("Blank PDF created successfully: output.pdf");
  }
}
</code></pre>

{% hint style="info" %}
**Info**

If you're signed in with an Apryse account, your license key is automatically prepopulated in all code snippets.
{% endhint %}

With this code, you can:

* Import the required Apryse `PDFNet` namespaces.
* Define a `main` method to serve as the starting point for execution.
* Initialize the Apryse SDK with a license key.
* Create a new PDF document, add a blank page, and save it as a linearized PDF.
* Log errors to the console.
* Output a simple message to confirm the program ran successfully.
  {% endtab %}

{% tab title="Maven" %}

1. In Visual Studio Code, open your project’s `pom.xml` file.
2. Add the `PDFNet Maven` repository and dependency in the `pom.xml` file and save:

{% code title="pom.xml" lineNumbers="true" %}

```xml
<project>
  . . .
  <repositories>
    <repository>
      <id>pdftron</id>
      <name>PDFNet Maven</name>
      <url>https://pdftron.com/maven/release</url>
    </repository>
  </repositories>
  <dependencies>
    <dependency>
      <groupId>com.pdftron</groupId>
      <artifactId>PDFNet</artifactId>
      <!-- Check the Apryse release notes for the latest version number -->
      <version>12.0.0</version>
    </dependency>
  </dependencies>
</project>
```

{% endcode %}

{% hint style="info" %}
**Info**

The [maven-metadata.xml](https://pdfnet-maven.s3.us-west-2.amazonaws.com/release/com/pdftron/PDFNet/maven-metadata.xml) endpoint lists all published versions of the `com.pdftron:PDFNet` artifact, along with the latest and release versions. This is useful for determining which version to specify in your `pom.xml` dependency.
{% endhint %}

3. Add the following code to a Java file in `src/main/java/<your_package>/`, such as `src/main/java/com/example/app/Main.java`, update your license key, and save your changes:

<pre class="language-java" data-line-numbers><code class="lang-java">package com.example.app;

// Import exception handling
import com.pdftron.common.PDFNetException;
// Import core PDF functionality
import com.pdftron.pdf.*;
// Import low-level SDF (structured document format) classes
import com.pdftron.sdf.SDFDoc;

public class Main
{
  public static void main(String[] args)
  {
    // Initialize PDFNet library
    // Replace with your license key
    PDFNet.initialize("<code class="expression">visitor.claims.serverKey || "YOUR_LICENSE_KEY"</code>");
    try
    {
      // Create new PDF and add blank page
      PDFDoc doc = new PDFDoc();
      Page page = doc.pageCreate();
      doc.pagePushBack(page);
        
      // Save as a linearized (web-optimized) PDF
      doc.save("output.pdf", SDFDoc.SaveMode.LINEARIZED, null);
    }
    // Handle PDFTron-specific exceptions
    catch(PDFNetException e)
    {
      e.printStackTrace();
      System.out.println(e);
    }

    // Print simple console output to confirm program ran
    System.out.println("Blank PDF created successfully: output.pdf");
  }
}
</code></pre>

{% hint style="info" %}
**Info**

If you're signed in with an Apryse account, your license key is automatically prepopulated in all code snippets.
{% endhint %}

With this code, you can:

* Import the required Apryse `PDFNet` namespaces.
* Define a `main` method to serve as the starting point for execution.
* Initialize the Apryse SDK with a license key.
* Create a new PDF document, add a blank page, and save it as a linearized PDF.
* Log errors to the console.
* Output a simple message to confirm the program ran successfully.
  {% endtab %}

{% tab title="Gradle" %}

1. In Visual Studio Code, open your top-level `build.gradle` file.
2. Add the `PDFNet Maven` repository and dependency to your `build.gradle` file and save:

{% code title="build.gradle" lineNumbers="true" %}

```groovy
plugins {
  id 'java'
  id 'application'
}

repositories {
  mavenCentral()
  maven {
    url "https://pdftron.com/maven/release/"
  }
}

dependencies {
  // Check the Apryse release notes for the latest version number
  implementation "com.pdftron:PDFNet:12.0.0"
}

application {
  mainClass = 'com.example.app.Main'
}
```

{% endcode %}

{% hint style="info" %}
**Info**

If the `plugins`, `repositories`, or `dependencies` blocks already exist, add the new entries to them instead of creating duplicate sections.
{% endhint %}

{% hint style="info" %}
**Info**

The [maven-metadata.xml](https://pdfnet-maven.s3.us-west-2.amazonaws.com/release/com/pdftron/PDFNet/maven-metadata.xml) endpoint lists all published versions of the `com.pdftron:PDFNet` artifact, along with the latest and release versions. This is useful for determining which version to specify in your `pom.xml` dependency.
{% endhint %}

3. Add the following code to a Java file in `src/main/java/<your-package>/`, such as `src/main/java/com/example/app/Main.java`, update your license key, and save your changes:

<pre class="language-java" data-line-numbers><code class="lang-java">package com.example.app;

// Import exception handling
import com.pdftron.common.PDFNetException;
// Import core PDF functionality
import com.pdftron.pdf.*;
// Import low-level SDF (structured document format) classes
import com.pdftron.sdf.SDFDoc;

public class Main
{
  public static void main(String[] args)
  {
    // Initialize PDFNet library
    // Replace with your license key
    PDFNet.initialize("<code class="expression">visitor.claims.serverKey || "YOUR_LICENSE_KEY"</code>");
    try
    {
      // Create new PDF and add blank page
      PDFDoc doc = new PDFDoc();
      Page page = doc.pageCreate();
      doc.pagePushBack(page);
      
	  // Save as a linearized (web-optimized) PDF
      doc.save("output.pdf", SDFDoc.SaveMode.LINEARIZED, null);
    }
    // Handle PDFTron-specific exceptions
    catch(PDFNetException e)
    {
      e.printStackTrace();
      System.out.println(e);
    }

    // Print simple console output to confirm program ran
    System.out.println("Blank PDF created successfully: output.pdf");
  }
}
</code></pre>

{% hint style="info" %}
**Info**

If you're signed in with an Apryse account, your license key is automatically prepopulated in all code snippets.
{% endhint %}

With this code, you can:

* Import the required Apryse `PDFNet` namespaces.
* Define a `main` method to serve as the starting point for execution.
* Initialize the Apryse SDK with a license key.
* Create a new PDF document, add a blank page, and save it as a linearized PDF.
* Log errors to the console.
* Output a simple message to confirm the program ran successfully.
  {% endtab %}
  {% endtabs %}

## 3. Verify your output

Finally, build and run your Java application to confirm that the Apryse Server SDK is working correctly. After the application runs successfully, it will generate a blank PDF file locally. Instructions are provided for manual, Maven, and Gradle-based integrations.

{% tabs %}
{% tab title="Manual" %}

1. Navigate to the `PDFNetJava/Samples/MyApp/java` directory.
2. In the terminal, run this command to compile `MyApp.java` with the `PDFNet.jar` file added to the Java classpath:

{% code lineNumbers="true" %}

```bash
javac -cp .:../../../Lib/PDFNet.jar MyApp.java
```

{% endcode %}

3. Launch the application and load the Apryse Server SDK Java and native library dependencies:

{% code lineNumbers="true" %}

```bash
java -Djava.library.path=../../../Lib -classpath .:../../../Lib/PDFNet.jar MyApp 
```

{% endcode %}

A successful output looks similar to:

{% code lineNumbers="true" %}

```bash
PDFNet is running in demo mode.
PackageV2: base
Blank PDF created successfully: output.pdf
```

{% endcode %}

4. Verify a blank `output.pdf` file was generated in the `/PDFNetJava/Samples/MyApp/java` directory. The folder structure looks similar to:

{% code lineNumbers="true" %}

```
PDFNetJava/
├── Doc/
├── Samples/
│   ├── MyApp/
│   │   └── java/
│   │       ├── output.pdf
│   │       ├── MyApp.class
│   │       └── MyApp.java
│   ├── HandwritingOCRTest/
│   └── ... (other sample folders)
```

{% endcode %}
{% endtab %}

{% tab title="Maven" %}

1. From the root of your Maven project, compile the application and download all required dependencies:

{% code lineNumbers="true" %}

```bash
mvn compile
```

{% endcode %}

2. After the project compiles successfully, start the application and generate the PDF:

{% code lineNumbers="true" %}

```bash
mvn exec:java -Dexec.mainClass=com.example.app.Main
```

{% endcode %}

3. Check the terminal output to ensure a successful build. A successful output looks similar to:

{% code lineNumbers="true" %}

```bash
PDFNet is running in demo mode.
Package: base
Blank PDF created successfully: output.pdf
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.903 s
[INFO] Finished at: 2026-06-24T12:11:21-04:00
[INFO] ------------------------------------------------------------------------
```

{% endcode %}

4. Verify that the Server SDK generated a blank `output.pdf` file in the root of your Java project.
   {% endtab %}

{% tab title="Gradle" %}

1. From the root of your Gradle project, run this command to build and start the application:

{% code lineNumbers="true" %}

```bash
./gradlew run
```

{% endcode %}

2. Check the terminal output to ensure a successful build. A successful output looks similar to:

{% code lineNumbers="true" %}

```bash
PDFNet is running in demo mode.
Package: base
Blank PDF created successfully: output.pdf

BUILD SUCCESSFUL in 3s
```

{% endcode %}

3. Verify that the Server SDK generated a blank `output.pdf` file in the root of your Java project.
   {% endtab %}
   {% endtabs %}
   {% endtab %}
   {% endtabs %}

## Next steps

<a href="/core/basic-operations/basics.md" class="button primary">Usage</a><a href="/core/get-started/readme.md" class="button primary">Guides</a><a href="/core/get-started/samples.md" class="button primary">Samples</a><a href="/core/get-started/readme/api.md" class="button primary">API docs</a>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/core/get-started/languages/java.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
