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

Native Java PDFProcessor 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.processor.*;.

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 PDFProcessorException.

The PDFProcessor class does not have a dispose() method, it is simply garbage collected. Each member function inside PDFProcessor, except the getter/setter functions, launches an individual external worker process. Even if a function throws, the external process quits automatically. That means you can use PDFProcessor without worrying about resource management.

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

PDFProcessor processor = new PDFProcessor();
int numberOfPages = processor.GetPageCount("c:\\test\\input.pdf");

The PDFProcessorHandle class has a dispose() method, which means it really needs to be deterministically disposed. Relying on the garbage collector is not recommended, because each PDFProcessorHandle 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 PDFProcessorHandle object is disposed.

The PDFProcessorHandle 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 PDFProcessorHandle, 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:

PDFProcessor processor = new PDFProcessor();
PDFProcessorHandle handle = null;
try
{
   handle = processor.OpenFile("c:\\test\\input.pdf", "c:\\test\\output.pdf", "");
   int numberOfPages = handle.GetPageCount();
}
catch(PDFProcessorException e)
{
   System.out.println(e);
}
finally
{
   if(handle != null)
      handle.dispose();
}

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

PDFProcessor'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 PDFProcessor object is extremely lightweight, like creating a Color object.

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