Some test text!

menu
search
Step by stepkeyboard_arrow_down

Get started with Java

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

Get started with Java

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

linkPrerequisites

  • JDK >= 5.

    Make sure that the JDK has been added to your path environment variable.

    The Troubleshooting section has more information about some of the common Java installation issues.

  • PDFTron SDK for Windows
    64-bit Download
    32-bit Download

linkInitial setup

Extract the folder from the .zip file.

This article uses PDFNET_BASE as the path into the PDFNetDotNet4 folder that you extracted.

PDFNET_BASE = path/to/extraction/folder/PDFNetC(64)/

linkRun 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 PDFTron 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.

linkIntegrate into your application

This is called the "PDFTron Hello World" application. It is easy to integrate the rest of PDFTron 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:

    import java.io.File;
    import java.io.IOException;
    
    // These are the most important packages to import
    // for basic document manipulation. 
    import com.pdftron.common.PDFNetException;
    import com.pdftron.pdf.*;
    import com.pdftron.sdf.SDFDoc;
    
    import java.io.*;
    
    public class HelloWorld
    {
        // Just a simple setup for the application
        public static void main(String[] args)
        {
            // PDFNet must always be initialized before any PDFTron
            // classes and methods can be used
            PDFNet.initialize();
            System.out.println("Hello World!");
    
            // Most PDFTron operations are required to be wrapped in
            // a try-catch block for PDFNetException, or in a method/class that
            // throws PDFNetException
            try {
                // Creates a new PDFDoc object
                PDFDoc doc = new PDFDoc();
    
                // Creating a new page and adding it
                // to document's sequence of pages
                Page page1 = doc.pageCreate();
                doc.pagePushBack(page1);
    
                // Files can be saved with various options
                // Linearized files are the most effective
                // for opening and viewing quickly on various platforms
                doc.save(("linearized_ouput.pdf"), SDFDoc.SaveMode.LINEARIZED, null);
    
                doc.close();
            } catch (PDFNetException e) {
                System.out.println(e);
                e.getStackTrace();
            }
            PDFNet.terminate();
        }
    }

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

    javac -cp .;../../Lib/PDFNet.jar HelloWorld.java
    
    java.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.

linkNext step

GuidesAPI docsSamples

linkTroubleshooting

Java installation issues
More information about JDK installation, possible issues and their respective fixes.

Get the answers you need: Support

close

Free Trial

Get unlimited trial usage of PDFTron SDK to bring accurate, reliable, and fast document processing capabilities to any application or workflow.

Select a platform to get started with your free trial.

Unlimited usage. No email address required.

PDFTron Receives USD$71 Million Growth Investment Led By Silversmith Capital Partners

Learn More
close