DataExtractor Class
Provides functionality to detect and extract structural components such as tables, form fields, text segments, paragraphs, and embedded images.
Inheritance
Namespace: Syncfusion.SmartDataExtractor
Assembly: Syncfusion.SmartDataExtractor.Base.dll
Syntax
public class DataExtractor : Object
Constructors
DataExtractor()
Initializes a new instance of the DataExtractor class.
Declaration
public DataExtractor()
Properties
ConfidenceThreshold
Minimum confidence (0.0–1.0) required for detected elements to be included in results. Default: 0.6
Declaration
public double ConfidenceThreshold { get; set; }
Property Value
| Type |
|---|
| System.Double |
EnableFormDetection
When true, form detection/recognition will be performed. Defaults to true.
Declaration
public bool EnableFormDetection { get; set; }
Property Value
| Type |
|---|
| System.Boolean |
EnableTableDetection
When true, table detection/extraction will be performed. Defaults to true.
Declaration
public bool EnableTableDetection { get; set; }
Property Value
| Type |
|---|
| System.Boolean |
FormRecognizeOptions
Options that control form recognition behavior.
Declaration
public FormRecognizeOptions FormRecognizeOptions { get; set; }
Property Value
| Type |
|---|
| FormRecognizeOptions |
OCRProcessor
Gets or sets the OCRProcessor instance used for OCR operations. If no instance is set, a new instance is created and returned.
Declaration
public OCRProcessor OCRProcessor { get; set; }
Property Value
| Type |
|---|
| OCRProcessor |
PageRange
Specific pages to process (1-based). If null, all pages are processed.
Declaration
public int[, ] PageRange { get; set; }
Property Value
| Type |
|---|
| System.Int32[,] |
SaveOptions
Gets the save options while extracting data to markdown.
Declaration
public SaveOptions SaveOptions { get; }
Property Value
| Type |
|---|
| SaveOptions |
Examples
int imagecount = 1;
DataExtractor dataExtractor = new DataExtractor();
string inputPath = @"AllImagePdf.pdf";
dataExtractor.SaveOptions.ImageNodeVisited += SaveImage;
using (FileStream inputStream = new FileStream(inputPath, FileMode.Open, FileAccess.Read))
{
string markdownText = dataExtractor.ExtractDataAsMarkdown(inputStream);
File.WriteAllText(@"AllImagePdf.md", markdownText);
}
//Helper method to handle image saving
static void SaveImage(object sender, SaveImageNodeVisitedEventArgs args)
{
string imagepath = $@"Image_{imagecount}.png";
using (FileStream fileStreamOutput = File.Create(imagepath))
{
args.ImageStream.CopyTo(fileStreamOutput);
}
args.Uri = imagepath;
imagecount++;
}
TableExtractionOptions
Options that control table detection and extraction behavior.
Declaration
public TableExtractionOptions TableExtractionOptions { get; set; }
Property Value
| Type |
|---|
| TableExtractionOptions |
Methods
ExtractDataAsExcel(Stream)
Creates and returns an Excel workbook containing the extracted data from the specified PDF or Image stream.
Declaration
public IWorkbook ExtractDataAsExcel(Stream inputStream)
Parameters
| Type | Name | Description |
|---|---|---|
| System.IO.Stream | inputStream | The input PDF or Image stream to be processed. |
Returns
| Type | Description |
|---|---|
| IWorkbook | An IWorkbook containing the converted PDF content. |
ExtractDataAsHtml(Stream)
Creates and returns the HTML representation of the extracted data from the specified PDF or Image stream.
Declaration
public string ExtractDataAsHtml(Stream inputStream)
Parameters
| Type | Name | Description |
|---|---|---|
| System.IO.Stream | inputStream | The input PDF or Image stream to be processed. |
Returns
| Type | Description |
|---|---|
| System.String | The extracted document content formatted as an HTML System.String. |
ExtractDataAsJson(Stream)
Declaration
public string ExtractDataAsJson(Stream stream)
Parameters
| Type | Name | Description |
|---|---|---|
| System.IO.Stream | stream |
Returns
| Type |
|---|
| System.String |
ExtractDataAsJsonAsync(Stream, CancellationToken)
Asynchronously extracts structured data (tables/forms) and returns JSON.
Declaration
public Task<string> ExtractDataAsJsonAsync(Stream inputStream, CancellationToken cancellationToken = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.IO.Stream | inputStream | A readable stream containing an image or PDF. |
| System.Threading.CancellationToken | cancellationToken | Token to observe while waiting for the task to complete. |
Returns
| Type | Description |
|---|---|
| System.Threading.Tasks.Task<System.String> | A task whose result is a JSON string representing extracted content. |
ExtractDataAsMarkdown(Stream)
Extracts structured data and returns a structured MarkdownDocument. This runs the same OCR/detection pipeline and returns a best-effort Markdown DOM.
Declaration
public string ExtractDataAsMarkdown(Stream inputStream)
Parameters
| Type | Name | Description |
|---|---|---|
| System.IO.Stream | inputStream |
Returns
| Type |
|---|
| System.String |
ExtractDataAsMarkdownAsync(Stream, CancellationToken)
Asynchronously extracts structured data and returns a Markdown string.
Declaration
public Task<string> ExtractDataAsMarkdownAsync(Stream inputStream, CancellationToken cancellationToken = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.IO.Stream | inputStream | A readable stream containing an image or PDF. |
| System.Threading.CancellationToken | cancellationToken | Token to observe while waiting for the task to complete. |
Returns
| Type | Description |
|---|---|
| System.Threading.Tasks.Task<System.String> | A task whose result is a Markdown string representing extracted content. |
ExtractDataAsMarkdownDocument(Stream)
Extracts structured content from the input stream and converts it into a Markdown document.
Declaration
public MarkdownDocument ExtractDataAsMarkdownDocument(Stream inputStream)
Parameters
| Type | Name | Description |
|---|---|---|
| System.IO.Stream | inputStream | A readable stream containing an image or PDF. |
Returns
| Type | Description |
|---|---|
| MarkdownDocument | A MarkdownDocument representing the extracted Markdown content. |
ExtractDataAsPdfDocument(Stream)
Declaration
public PdfLoadedDocument ExtractDataAsPdfDocument(Stream inputStream)
Parameters
| Type | Name | Description |
|---|---|---|
| System.IO.Stream | inputStream |
Returns
| Type |
|---|
| PdfLoadedDocument |
ExtractDataAsPdfDocumentAsync(Stream, CancellationToken)
Declaration
public Task<PdfLoadedDocument> ExtractDataAsPdfDocumentAsync(Stream inputStream, CancellationToken cancellationToken = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.IO.Stream | inputStream | |
| System.Threading.CancellationToken | cancellationToken |
Returns
| Type |
|---|
| System.Threading.Tasks.Task<PdfLoadedDocument> |
ExtractDataAsPdfStream(Stream)
Declaration
public Stream ExtractDataAsPdfStream(Stream inputStream)
Parameters
| Type | Name | Description |
|---|---|---|
| System.IO.Stream | inputStream |
Returns
| Type |
|---|
| System.IO.Stream |
ExtractDataAsPdfStreamAsync(Stream, CancellationToken)
Declaration
public Task<Stream> ExtractDataAsPdfStreamAsync(Stream inputStream, CancellationToken cancellationToken = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.IO.Stream | inputStream | |
| System.Threading.CancellationToken | cancellationToken |
Returns
| Type |
|---|
| System.Threading.Tasks.Task<System.IO.Stream> |
ExtractDataAsPresentation(Stream)
Creates and returns a PowerPoint presentation containing the extracted data from the specified PDF or Image stream.
Declaration
public IPresentation ExtractDataAsPresentation(Stream inputStream)
Parameters
| Type | Name | Description |
|---|---|---|
| System.IO.Stream | inputStream | The input PDF or Image stream to be processed. |
Returns
| Type | Description |
|---|---|
| IPresentation | An IPresentation containing the converted PDF content, with one slide generated for each detected page. |
ExtractDataAsWordDocument(Stream)
Creates and returns a Word document containing the extracted data from the specified PDF or Image stream.
Declaration
public WordDocument ExtractDataAsWordDocument(Stream inputStream)
Parameters
| Type | Name | Description |
|---|---|---|
| System.IO.Stream | inputStream | The input PDF or Image stream to be processed. |
Returns
| Type | Description |
|---|---|
| WordDocument | A WordDocument containing the converted PDF content. |
ExtractKeyValuePairs(Stream)
Extracts key-value pair data from the specified PDF or image document and returns it as a formatted JSON string.
Declaration
public string ExtractKeyValuePairs(Stream inputStream)
Parameters
| Type | Name | Description |
|---|---|---|
| System.IO.Stream | inputStream | The input PDF or Image stream to be processed. |
Returns
| Type | Description |
|---|---|
| System.String | A JSON string representing the extracted key-value pairs and their associated document structure. |