Java PDF library integration

Welcome to Apryse. Java for the Apryse SDK is cross-platform and supported on Windows, macOS and Linux. To get started, choose your preferred platform from the tabs below.

Windows Java PDF library integration

This guide will help you run Apryse samples and integrate a free trial of the Apryse SDK into Java applications on Windows. Your free trial includes unlimited trial usage and support from solution engineers.

Prerequisites

  • JDK >= 5.Make sure that the JDK has been added to your path environment variable.Please visit the Java FAQ section for more information about some of the common Java installation issues.
  • Apryse's Java PDF library for Windows:

Download the SDK

download 64-bit for Windows

Run Apryse SDK in production

A commercial license key is required for use in a production environment. Please contact sales to purchase a commercial key or if you need any other license key assistance.

Keep your commercial license key confidential.

License keys are uniquely generated. Please make sure that it is not publicly available (e.g. in your public GitHub).

Initial setup

  1. Extract the folder from the .zip file.
  2. 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 the samples

Navigate to the location of extracted contents. Find and enter the Samples folder. Here you can find sample code for a large number of features supported by the Apryse SDK.

Run a specific sample

  1. Find the sample you want to run and navigate into the JAVA folder inside.
  2. Find RunTest.bat and run it. This can be done using either CLI or with a double-click. The results should appear on a cmd window.

Run all samples

  1. Find runall_java.bat in the samples folder and double click it to run it. The results should appear on a cmd window.

Integrate into your application

This is called the "Apryse Hello World" application. It is easy to integrate the rest of Apryse SDK if you are able to open, save and close a PDFDoc.

  1. Create a new folder in Samples by the name HelloWorld.
  2. In the HelloWorld folder, create a new file called HelloWorld.java, open and edit it using your favorite text editor.
  3. Insert the following to your file:

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}

To test that your code works, compile and run the code using a shell in the HelloWorld folder using:

Java

1javac -cp .;../../Lib/PDFNet.jar HelloWorld.java
2java.exe -Djava.library.path=../../Lib -classpath .;../../Lib/PDFNet.jar HelloWorld

Once you have successfully run this, you should see an output file in the working directory of this program.

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales