OcrClient
Category: Web
Source: ocr_client.dart
Classes
OcrClient
Client for OCR-based PDF text extraction using LLM vision APIs.
Supports Mistral OCR Small (pixtral-based) and OpenAI vision models. Used as a fallback when pdftotext returns empty text (scanned PDFs).
Constructor
dart
OcrClient({
required this.provider,
required this.apiKey,
required this.model,
this.timeoutSeconds = 120,
http.Client? client,
})dart
factory OcrClient.fromConfig(PdfConfig config, {http.Client? client})dart
OcrClient(
provider: config.ocrProvider,
apiKey: config.ocrProvider == OcrProviderType.mistral
? config.mistralApiKey ?? ''
: config.openaiApiKey ?? '',
model: config.ocrProvider == OcrProviderType.mistral
? config.mistralModel
: config.openaiModel,
client: client,
)Properties
| Property | Type | Description |
|---|---|---|
provider | OcrProviderType | |
apiKey | String | |
model | String | |
timeoutSeconds | int | |
headers | Map<String, String> get | |
openaiEndpoint | String get | The OpenAI API endpoint for OCR requests. Uses the Responses API which natively supports PDF file inputs, unlike the Chat Completions API which only accepts images. |
openaiEndpoint | String get | The OpenAI API endpoint for OCR requests. Uses the Responses API which natively supports PDF file inputs, unlike the Chat Completions API which only accepts images. |
Methods
Future<String?> extractText(Uint8List pdfBytes)
Extract text from PDF bytes via OCR API.