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.

Linux 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 Linux. Your free trial includes unlimited trial usage and support from solution engineers.

Prerequisites

  • JDK version ≥ 5
  • Apryse SDK for Linux:

Download the SDK

download 64-bit for Linux

Download the SDK

download 32-bit for Linux

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

Run a specific sample

  1. Navigate to the JAVA folder in a sample project, for example /Samples/AddImageTest/JAVA and run the sample with

sh

1./RunTest.sh

Run all samples

  1. Navigate to /Samples and run

sh

1./runall_java.sh

The tests will run one by one.

Output files will be in /Samples/TestFiles/Output

Integrate into your application

This section will show you how to use our SDK to create a simple Apryse "Hello World!" application. It will create a document with one blank page and save it as a linearized PDF in its running directory.

  1. Navigate to the /Samples directory of the Apryse SDK and create a directory called myApp if it does not exist already. This guide will assume your project is named myApp.
  2. Enter your myApp directory and create a JAVA directory for organization. Then create a myApp.java file in the JAVA directory. Open this file in your favorite text editor and paste:

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}

3. Navigate back to your myApp project folder and compile your application using our PDFNet library:

Bash

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

4. Run the project by executing:

Bash

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

If all goes well, your terminal should output:

txt

1PDFNet is running in demo mode.
2Permission: write
3Hello World!

Check the output.pdf that the program output in the same directory. It should be a PDF with one blank page.

Next step

Troubleshooting

Check the troubleshooting page if you run into any issues going through this document.

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales