PDF Generation Template Editor
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
Before using OCR, Layout Analysis, Table Recognition you need to set the DocumentAI model path first.
SetDocumentAIModel supports an optional gpu_id parameter used to specify the GPU device index for the AI model. When gpu_id is -1, GPU acceleration is disabled.
The AI capabilities of ComPDF Conversion SDK (layout analysis, table recognition, OCR, orientation correction, and so on) depend on model files. The SDK package ships with the base model documentai.model, so the default configuration requires no extra download. Download an extension package only when you need higher accuracy or extended features, place it in a directory of your choice, and pass its path to LibraryManager.SetDocumentAIModel.
Download address (all model packages, including the base package): https://download.compdf.com/download/models
There is one base package and several extension packages:
| File | Size | Purpose | Availability / When needed |
|---|---|---|---|
documentai.model | about 230 MB | Base package: layout analysis, table recognition (balanced profile), and all basic OCR languages | Included in the SDK package; required for any AI feature (layout analysis, OCR, table recognition) |
table_legacy.model | about 270 MB | Table extension package: resources required by the high-accuracy profile | Separate download; only needed when you use the TableRecognitionAccuracy.e_HighAccuracy profile, not needed for the default balanced profile |
ocr_server.model | about 139 MB | High-accuracy OCR enhancement package, covering Chinese, English, Japanese, and other languages | Separate download; needed when you require higher OCR accuracy |
document_process.model | about 37 MB | Document orientation classification and skew correction | Separate download; needed when you use EnableDocumentOrientationClassification (orientation classification) or EnableDocumentDewarp (dewarping) |
The four files total about 676 MB. No extension package needs to be downloaded unless you need the extra features: the default configuration only uses the documentai.model shipped in the SDK package.
All model packages are loaded through the same interface:
// Load the base package first.
LibraryManager.SetDocumentAIModel("path/documentai.model", -1);
// Load extension packages when needed; capabilities that are already loaded are kept.
LibraryManager.SetDocumentAIModel("path/table_legacy.model", -1);
LibraryManager.SetDocumentAIModel("path/document_process.model", -1);gpu_id specifies the GPU device index used by the AI model. -1 means the GPU is not used, and the default is -1.ReleaseDocumentAIModel() releases all loaded models. You must load them again before using AI features afterwards.ErrorCode.e_ErrConverting is returned.documentai.model shipped in the SDK package is the version matching 4.3.0; please also download the 4.3.0 version of any extension package.documentai.model of 4.2.0 and earlier does not contain the resources required by the balanced profile, while 4.3.0 keeps the same file name. If you copied an older documentai.model into your own deployment directory or project, overwrite it with the new file from the 4.3.0 SDK package when upgrading; do not keep using the old file with the same name. Loading an old model returns an error and does not automatically fall back to the high-accuracy profile.| Symptom | Possible cause |
|---|---|
SetDocumentAIModel returns an error | Wrong path; the model file does not match the SDK version; the file is incomplete (interrupted download) |
Tables look different from (or worse than) expected after selecting HighAccuracy | table_legacy.model has not been loaded (tables fell back to rule-based recognition) |
A conversion returns ErrorCode.e_ErrLicenseOCRPermissionDeny (29) | The license does not include the OCR permission; unrelated to the model |
If you need to control the number of Layout Analysis and Table Recognition model instances, call SetDocumentAIModelCount:
// The first parameter is the number of Layout Analysis model instances,
// the second is the number of Table Recognition model instances.
LibraryManager.SetDocumentAIModelCount(1, 1);If this interface is not called, the default model instance count is 1 for both.
// Set the OCR model.
string modelPath = "***";
LibraryManager.SetDocumentAIModel(modelPath);This option is available only in SDK v4.1.0 or later. If you prefer to run OCR, Layout Analysis, or Table Recognition with your own model or a third-party service instead of the bundled DocumentAI model, the SDK exposes callback hooks on ConvertCallback that let you supply the results as JSON. See 3.12 Use Custom AI Models via Callbacks for details. When all three capabilities you need are covered by your own callbacks, SetDocumentAIModel does not have to be called.