BCL easyPDF SDK
easyPDF SDK Usermanual
PDF Creator Programming API  |  Download Free Trial  |  Contact Us to Purchase

Native Java PDFConverter API

Usage

The native Java API is very similar to the JACOB API, with only a few distinct differences.

First, you need to import com.bcl.easypdf.converter.*;.

The jar file is called easypdf.jar, and it is under c:\Program Files\Common Files\BCL Technologies\easyPDF 8\easypdf.jar.

Oracle JAVA SE Development Kit 1.5 or above is required.

COM exceptions were replaced by the new PDFConverterException.

The PDFConverter class has a dispose() method, which means it really needs to be deterministically disposed. Relying on the garbage collector is not recommended, because each PDFConverter object launches a separate worker process. Even though these worker processes are sleeping while not executing a function, they are still in the memory, and only really quit when the PDFConverter object is disposed.

The PDFConverter object should be treated as if it were an expensive resource, such as a file, mutex, or a database connection. If you would like to know what really is inside PDFConverter, it is just a named pipe. However, the worker process is programmed to only quit when the pipe is closed.

If the customer's application crashes, the system automatically closes all pipes belonging to the process, which means all related worker processes automatically quit as well.

The minimal Java sample code looks like this:
(Note: all Native Java sample code and declarations have a light red background color)

PDFConverter converter = new PDFConverter();
try
{
   converter.getPDF2Image().Convert("c:\\test\\input.pdf", "c:\\test\\output.jpg");
}
catch(PDFConverterException e)
{
   System.out.println(e);
}
finally
{
   converter.dispose();
}

The key here is the finally block, which calls dispose().

PDFConverter's constructor is designed to never throw exceptions. That's because it does not launch a worker process and does not create a named pipe, it merely initializes a few variables to their default values. In other words, creating a PDFConverter object is extremely lightweight, like creating a Color object.

However, as soon as you do anything else, even getting a property, it instantly launches a worker process.

Notification Events

Notification events are new to the Java API, as they did not exist in JACOB. Here is an example that catches OnPageStart, which is called before printing each page:

SampleEvents handler = new SampleEvents();
PDFConverter converter = new PDFConverter();
try
{
   converter.getPDFConverterMonitor().events = handler;
   converter.getPDF2Image().Convert("c:\\test\\input.pdf", "c:\\test\\output.jpg");
}
catch(PDFConverterException e)
{
   System.out.println(e);
}
finally
{
   converter.dispose();
}

SampleEvents is your class, where you have a chance to respond to all events:

import com.bcl.easypdf.converter.*;

public class SampleEvents implements IPDFConverterMonitorEvents
{
        public cnvMonitorResponse OnInitEventHandler()
        {
                return cnvMonitorResponse.CNV_MON_CONTINUE_CONVERSION;
        }

        public cnvMonitorResponse OnPageStartEventHandler(int pageNumber, int pageCount, String fileName)
        {
                System.out.print("Page ");
                System.out.print(pageNumber);
                System.out.print("...");
                return cnvMonitorResponse.CNV_MON_CONTINUE_CONVERSION;
        }

        public cnvMonitorResponse OnEndEventHandler(int errCode)
        {
                return cnvMonitorResponse.CNV_MON_CONTINUE_CONVERSION;
        }
}

Note that even if you just want to handle a single event, you are still required to handle them all at once.