Skip to content

Foxit PDF SDK Multithreading Safety Guide

Overview

Starting with v10.0, Foxit PDF SDK introduced built-in thread-safety mechanisms and enhanced multithreaded LibreOffice-to-PDF conversion support. From v11.0 onward, document-level multithreading support was further improved, especially for JavaScript, XFA, and document-level objects. To ensure stable and efficient SDK operation in multithreaded environments, developers must still follow specific usage guidelines and initialization procedures.

Thread-Safety Mechanisms

1. Compliance Engine Thread Safety

  • Version requirement: Starting with v10.0, compliance resource files provide a default thread-safety mechanism.
  • Initialization requirement: For multithreaded use, you must call the ComplianceEngine.initializeThreadContext API at the start of each new thread.
  • Usage order: After initializing the thread context, other compliance plugin APIs can be used safely.

2. Office to PDF Multithreading Support

  • Linux platform: On Linux x86/x64, a dedicated LibreOffice binary is provided to support multithreaded conversion.
  • Implementation: Assign the path to the architecture-specific binary engine to the engine_path parameter to enable multithreaded conversion.

Java example:

java
String engine_path = "/resource-folder/x64/fxoffice2pdf"; / Replace with the correct engine path.
Convert.fromWord(word_file_path, "", output_path, engine_path, word_convert_setting_data);

3. JavaScript and XFA Thread Safety

  • Version requirement: Starting with v11.0.0, the SDK enhanced thread-safety handling for JavaScript and XFA.
  • Initialization requirement: For the thread-safety mechanism, call the Library::Initialize() overload and set the bool enable_js_xfa_threadsafety parameter to true.

4. Document-Level Thread Safety

  • Architecture improvement: v11.0.0 improved the overall architecture and enhanced document-level thread safety.
  • Core rule: A single PDF document should be processed in only one thread to ensure data consistency and safety.

Platform Limitations

macOS Platform Limitations (Java)

  • Multithreading not supported: The Compliance engine in the macOS Java library does not currently support multithreaded operations.
  • Resource replacement requirement: Copy the pdfEngineLight.dylib file from the var\legacy directory in the resource package to compliance/mac.

Multithreading Usage Notes (Java Example)

💡 For detailed Java object release mechanics, see Foxit PDF SDK Java Object Management.

1. Initialization Order (Initialize Thread Context First)

java
// Correct multithreaded initialization order
ComplianceEngine.initializeThreadContext(); / Must be called first
// Then other compliance APIs can be used

2. Object Management

  • Manually release GSDK objects: Always release objects via the .delete() method to avoid memory leaks.
  • Release order: Release child objects before parent objects.
  • Do not rely on GC: Java garbage collection does not automatically release underlying C++ objects; you must manage them manually.

Example

java
PDFDoc doc = new PDFDoc("sample.pdf");
doc.load(null);
PDFPage page = doc.getPage(0);
Annot annot = page.addAnnot(Annot.e_Link, rectF);
Link link = new Link(annot);

// Recommended release order
link.delete();    / Child object
annot.delete();   / Annotation object
page.delete();    / Page object
doc.delete();     / Document object