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

Native Java PDFDocument 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.document.*;.

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

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

The PDFDocument 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 PDFDocument, 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)

PDFDocument document = new PDFDocument();
try
{
   document.getFormFields().getItem("My Text Field").setValue("Hello");
   document.SaveAs("C:\\test\\output.pdf");
   document.Close(false);
}
catch(PDFDocumentException e)
{
   System.out.println(e);
}
finally
{
   document.dispose();
}

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

PDFDocument'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 PDFDocument 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.