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.

set_document_ai_model 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.

Set AI Model Instance Count

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

Sample

ruby
model_path = "/path/to/documentai.model"
ComPDFKitConversion::LibraryManager.set_document_ai_model_count(1, 1)
code = ComPDFKitConversion::LibraryManager.set_document_ai_model(model_path, -1)
raise "set_document_ai_model failed: #{code}" unless code == ComPDFKitConversion::ErrorCode::SUCCESS