Extracts structured data from PDF documents and images with any AI provider.
TsgcAIDocumentExtractor reads PDF documents and images (invoices, receipts, identity documents or any document you describe with a JSON Schema) and returns the data they contain as a JSON document. It sends the document to an AI model through a linked TsgcAIChat, so every provider of TsgcAIChat can be used, and it checks the answer locally before returning it.
dpInvoice, dpReceipt or dpIDCard.rfJSONSchema) with a data member that follows your schema and, optionally, a confidence value per field.
PDF, PNG, JPEG, GIF and WEBP files. PDF input depends on the provider selected in the linked TsgcAIChat:
| Provider | Images | |
| aicpOpenAI | Yes | Yes |
| aicpAnthropic | Yes | Yes |
| aicpGemini | Yes | Yes |
| aicpDeepSeek | No | Yes |
| aicpGrok | No | Yes |
| aicpMistral | No | Yes |
| aicpOllama | No | Yes |
With OpenAI the schema is sent in strict mode: every object must declare "additionalProperties": false, every property must be listed in required, and optional values use a nullable type such as ["string","null"]. The presets already follow these rules. The local validation checks type, properties, required, items and enum, recursing into nested objects and arrays.
Link a TsgcAIOCRTesseract or a TsgcAIOCRWindows to OCR and set OCRMode to recognise the text of the images locally, either as a fallback when the vision request fails (domFallback) or always (domAlways), which lets a text only model extract the data. The local OCR accepts images only.
Two local OCR engines are available. TsgcAIOCRTesseract runs the Tesseract command line tool on Windows, Linux and macOS, and needs Tesseract installed. TsgcAIOCRWindows uses the OCR engine built into Windows 10 and later, so nothing has to be installed or deployed; it reads the OCR language packs installed in Windows.
oChat.Provider := aicpOpenAI;
oChat.ChatOptions.ApiKey := 'API_KEY';
oChat.ChatOptions.Model := 'gpt-4o-mini';
oExtractor.AIChat := oChat;
oExtractor.Preset := dpInvoice;
vJSON := oExtractor.ExtractFile('invoice.pdf');
The step by step guide Extract data from an invoice shows a complete example, with confidence checks and the OCR fallback.