Some test text!

menu
search
Javakeyboard_arrow_down

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

linkPrerequisites

linkInitial setup

  1. Download the PDFTron SDK.
  2. Extract via tar xvzf PDFNetC64.tar.gz or tar xvzf PDFNetC.tar.gz.

linkRun 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
./RunTest.sh

Run all samples

  1. Navigate to /Samples and run
./runall_java.sh

The tests will run one by one.

Output files will be in /Samples/TestFiles/Output

linkIntegrate into your application

This section will show you how to use our SDK to create a simple PDFTron "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 PDFTron 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. Open this file in your favorite text editor and paste:

    import java.io.File;
    import java.io.IOException;
    
    import com.pdftron.common.PDFNetException;
    import com.pdftron.pdf.*;
    import com.pdftron.sdf.SDFDoc;
    import com.pdftron.sdf.ObjSet;
    import com.pdftron.sdf.Obj;
    
    public class myApp
    {
        public static void main(String[] args)
        {
            PDFNet.initialize();  // PDFNet must be initialized before accessing any PDFTron API
            try
            {
                PDFDoc doc = new PDFDoc();
                Page page = doc.pageCreate();  // Start a new page
                doc.pagePushBack(page);  // Add the page to the document
                doc.save("output.pdf", SDFDoc.SaveMode.LINEARIZED, null);  // Save the document as a linearized PDF
            }
            catch(PDFNetException e)
            {
                e.printStackTrace();
                System.out.println(e);
            }
            System.out.println("Hello World!");
        }
    }
  3. Navigate back to your myApp project folder and compile your application using our PDFNet library:

    javac -cp .:../../../Lib/PDFNet.jar myApp.java
  4. Run the project by executing:

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

    If all goes well, your terminal should output:

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

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

linkNext step

GuidesAPI docsSamples

linkTroubleshooting

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

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