Skip to content
ComPDF

Set DocumentAI Model

Overview

Before using OCR, Layout Analysis, or Table Recognition, you need to set the DocumentAI model path first.

setDocumentAIModel supports an optional gpuId parameter used to specify the GPU device index for the AI model. When gpuId is -1, GPU acceleration is disabled.

Set AI Model Instance Count

If you need to control the number of Layout Analysis and Table Recognition model instances, call setDocumentAIModelCount.

Sample

js
const modelPath = "/path/to/documentai.model";
sdk.setDocumentAIModelCount(1, 1);
const code = sdk.setDocumentAIModel(modelPath, -1);
if (code !== 0) {
  throw new Error(`setDocumentAIModel failed: ${code}`);
}

When the conversion work is done, call releaseDocumentAIModel() if a DocumentAI model was loaded.

js
sdk.releaseDocumentAIModel();