Initializing APDFL: Initialization and Termination Process

The procedure for initializing the Adobe PDF Library defines font locations, memory management routines and resource allocation in preparation for document processing.

Single-Threaded Applications

In a single-threaded application, the initialization and termination processes only needs to be called once during the life of the application. Attempting to initialize the Adobe PDF Library more than once may cause errors or unpredictable behavior, and is not supported. You are free, however, to create multiple documents and/or multiple files within the run. Also, you may choose to initialize and then terminate the Adobe PDF Library repeatedly, in sequence, if you like. That might be necessary to release memory used during processing.

Multi-Threaded Applications

In a multi-threaded application, each thread that will use the Adobe PDF Library must initialize and terminate the Library. This includes the main process for single-threaded programs. The reason is that the first initialization of the Library requires some extra processing that later initializations do not, such as building of font resource lists. By keeping an initialized Library instance open in the parent process, you can improve the initialization time for every child process. Otherwise, if you have a point in the process where no child has the Library open, the next one to initialize will have to do a full startup again.

Thus we strongly recommend, whenever possible, that you initialize the Adobe PDF Library in the main process thread before initializing any other threads, and terminate the Library in the main process thread after terminating in other threads.

The Adobe PDF Library will perform cleanup work during termination if no other instances are active.  This causes the Library to not initialize correctly for any follow-on processes afterwards.

Therefore, though each thread must call PDFLInit/PDFLTerm, take care that the Adobe PDF Library is not re-initialized after the last outstanding initialization has been terminated.

For example, this sequence will cause errors when attempting to initialize Thread 2:

[Thread 1 processing]
[Thread 2 processing]

The problem above is that when Thread 1 terminates, no other processes are seen, and so shutdown cleanup work begins, leading to errors when the initialization of Thread 2 begins.

This sequence is recommended instead:

[thread 1 processing]
[thread 2 processing]