TsgcAIDocumentExtractor › Methods › ExtractFile
Extracts the data of one PDF or image file and returns it as JSON.
function ExtractFile(const aFileName: string): string;
| Name | Type | Description |
|---|---|---|
aFileName | const string | Full path of the PDF or image file. |
The extracted data as a JSON document, the same text as LastResult.Data. (string)
The file is read and sent as an attachment of the user message. The media type comes from the extension: .pdf, .png, .jpg, .jpeg, .gif and .webp are accepted, any other extension raises EsgcAIChat. PDF files are accepted by OpenAI, Anthropic and Gemini; DeepSeek, Grok, Mistral and Ollama accept images only.
After the answer is read it is validated, retried when needed (ValidationRetries), the confidences are parsed, OnLowConfidence is raised for the weak fields and OnExtracted is raised with the result.
Raises EsgcAIDocumentExtractor when AIChat is not assigned, when the schema is empty or invalid, when there is nothing to extract, when OCRMode needs an OCR that is not assigned, and when the data does not validate and RaiseOnInvalid is True. Transport and provider errors of the chat propagate to the caller as they are, they do not reach OnChatError.
oExtractor.Preset := dpInvoice;
vJSON := oExtractor.ExtractFile('C:\invoices\invoice.pdf');