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

Native Python PDFProcessor API

Using PDFProcessor

The native Python API, which is written in Python 3, is a thin interface around a binary executable. It is very similar to the native .NET API, with the exception of some language-specific differences.

Note: there is no native Python 2 API. That was a very different language than Python 3.

In order to use easyPDF, just import the library by adding import easyPDFProcessor. The PDFProcessor SDK is inside the BCL\easyPDF\PDFProcessor\ namespace. easyPDFProcessor.py can be found under C:\Program Files\Common Files\BCL Technologies\easyPDF 8.

When an error occurs, an exception of type PDFProcessorException is thrown.

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 Python sample code looks like this:

import easyPDFProcessor
processor = easyPDFProcessor.PDFProcessor()
try:
   print(processor.GetPageCount("c:\\test\\input.pdf", ""))
except easyPDFProcessor.PDFProcessorException as ex:
   print(ex)

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.

Using PDFProcessorHandle

It is not possible to create a PDFProcessorHandle object directly. Instead, handle instances are created using PDFProcessor's OpenFile or OpenMem method.

The PDFProcessorHandle class has a destructor, which means it is automatically disposed when the object goes out of scope. That makes memory management trivial, just make sure you are not holding on to the variable when you are no longer using the SDK.

The minimal Python sample code looks like this:

import easyPDFProcessor
processor = easyPDFProcessor.PDFProcessor()
handle = None
try:
   handle = processor.OpenFile("c:\\test\\input.pdf", "c:\\test\\output.pdf", "")
   print(handle.GetPageCount())
   pageSize = handle.GetPageSize(0)
   print("Page 1's size: %g x %g pt" % (pageSize.width, pageSize.height))
except easyPDFProcessor.PDFProcessorException as ex:
   print(ex)
finally:
   if handle:
      handle.Close()
      handle = None

Launch Timeout

Launching the worker process and connecting the named pipe should happen very fast, in milliseconds. However, under an abnormally heavy load, the computer may not have enough cycles to perform this task in a timely fashion.

The native Python API has an internal timeout built-in. The default value is 1 minute. This is because a server may momentarily slow down so much that it is not responding for seconds, but it usually recovers after a while.

The default timeout value can be changed via the launchTimeout member (in milliseconds). This must be performed immediately after the creation of the PDFProcessor object.

processor = easyPDFProcessor.PDFProcessor()
try:
   $processor.launchTimeout = 60000
   print(processor.GetPageCount("c:\\test\\input.pdf", ""))
except easyPDFProcessor.PDFProcessorException as ex:
   print(ex)

Upon timeout an exception is thrown, and the SDK cannot be used. Another attempt may be made later.