Extract data as Excel from PDF or Image
4 Nov 20263 minutes to read
The Smart Data Extractor enables you to process PDF documents or scanned images and export the structured content as Excel (XLSX DOM).
This section covers two scenarios:
- Extracting data as Excel from a PDF document.
- Extracting data as Excel from an image.
Extract Data as Excel from PDF
To extract structured data from a PDF document using the ExtractDataAsExcel method of the DataExtractor class, refer to the following code example:
using Syncfusion.SmartDataExtractor;
using Syncfusion.XlsIO;
//Open the input PDF file as a stream.
using (FileStream stream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read))
{
//Initialize the Data Extractor.
DataExtractor extractor = new DataExtractor();
//Extract data as Excel.
IWorkbook excel = extractor.ExtractDataAsExcel(stream);
//Save the extracted Excel data into an output file.
excel.SaveAs("Output.xlsx");
excel.Close();
}You can download a complete working sample from GitHub.
Extract Data as Excel from Image
To extract structured data from an image file using the ExtractDataAsExcel method of the DataExtractor class, refer to the following code example:
using Syncfusion.SmartDataExtractor;
using Syncfusion.XlsIO;
//Open the input image file as a stream.
using (FileStream stream = new FileStream("Input.png", FileMode.Open, FileAccess.Read))
{
//Initialize the Data Extractor.
DataExtractor extractor = new DataExtractor();
//Extract data as Excel.
IWorkbook excel = extractor.ExtractDataAsExcel(stream);
//Save the extracted Excel data into an output file.
excel.SaveAs("Output.xlsx");
excel.Close();
}Supported and Unsupported PDF Elements
The following table lists the PDF elements and their preservation details in the Excel
| PDF Elements | Supported |
|---|---|
| Title, Text | Yes |
| Image | Yes |
| Table | Yes |
| Nested Table | No |
| Text Inline Styles | Yes (Bold and Italic) |
| Subscript, Superscript | Yes (Searchable PDF documents only) |
| Underline, Strikethrough | No |
| List | No (Converted as line-by-line text) |
| Charts and Barcodes | Yes (Preserved as images) |
| Code blocks, Header, Footer, Page Number | Yes (Preserved as text) |
| Link | No (Preserved as plain text) |
| Text color and Background color | No |
| Logo in page header or footer | No |