PDF Generation Template Editor
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
ComPDF Conversion SDK supports converting PDF documents to Microsoft Excel format (.xlsx). By extracting, parsing, and importing data from PDF into Excel, users can further edit, analyze, or share Excel files. This feature helps increase productivity, reduce manual entry errors, and simplify complex document processing tasks.
This format uses only the following options of ConvertOptions; the other options have no effect:
| Option | Default | Meaning |
|---|---|---|
excel_csv_format | false | Must be off to output an .xlsx workbook; when on, CSV is output instead (see "PDF to CSV"). |
excel_worksheet_option | ExcelWorksheetOption::e_ForTable | ExcelWorksheetOption::e_ForTable: one worksheet per table, tables only; ExcelWorksheetOption::e_ForPage: one worksheet per page; ExcelWorksheetOption::e_ForDocument: all content on one worksheet. Image input without OCR always uses ExcelWorksheetOption::e_ForPage. |
excel_all_content | false | Also writes the content outside tables (text, images, headers and footers); when off, only tables are kept. Ignored with ExcelWorksheetOption::e_ForTable. |
enable_ai_layout | true | Uses AI layout analysis to recognize paragraphs, tables, images, headers and footers, and formulas; when off, rule-based layout analysis is used. Ignored if the license does not include AI layout analysis. |
enable_ai_table_recognition | true | Recognizes the structure of tables with the table model; when off, the table structure is rebuilt from the ruling lines. Only applies to tables found by AI layout analysis (enable_ai_layout on). |
table_recognition_accuracy | TableRecognitionAccuracy::e_Balanced | Table model: TableRecognitionAccuracy::e_Balanced uses the base documentai.model, TableRecognitionAccuracy::e_HighAccuracy uses the table_legacy.model package. Only takes effect when AI table recognition runs with the built-in table model. If the model of the requested accuracy is not loaded, the conversion still succeeds and tables fall back to rule-based recognition. |
contain_image | true | Keeps the images and vector graphics of the source. Only visible when content outside tables is written (excel_all_content on with ExcelWorksheetOption::e_ForPage or ExcelWorksheetOption::e_ForDocument); tables-only output never contains images. |
contain_annotation | true | Outputs the appearance of annotations as images. Only for PDF pages that are not recognized by OCR, and only visible when content outside tables is written. |
enable_ocr | false | Recognizes text with OCR on the pages chosen by ocr_option. Ignored if the license does not include OCR. |
ocr_option | OCROption::e_All | Which content OCR handles: OCROption::e_All every page; OCROption::e_ScanPage only image (scanned) pages; OCROption::e_InvalidCharacter re-recognizes unreadable characters on the other pages; OCROption::e_InvalidCharacterAndScanPage both. Only takes effect when enable_ocr is on. |
languages / language_count | language_count = 0 | OCR recognition languages; when no language is given, English is used. Only takes effect when enable_ocr is on. |
enable_document_orientation_classification | false | Detects the page rotation and turns the page image upright before OCR. Only takes effect when enable_ocr is on. |
enable_document_dewarp | false | Flattens curved or warped page photos before OCR. Only takes effect when enable_ocr is on. |
formula_to_image | true | Outputs formulas as pictures; when off, as text. Only applies to formulas found by AI layout analysis, and only visible when content outside tables is written. |
font_name | Empty | Uses the given font for all text, e.g. "Arial"; empty selects fonts automatically. Silently ignored if the font is neither embedded in the PDF nor installed on the system. |
output_document_per_page | false | Writes one workbook per page instead of one workbook. |
page_ranges | Empty | Pages to convert, e.g. "1-3,5,7-9"; empty converts every page. For multi-frame image input it selects the frames. |
enable_auto_page_size | false | Image input only: sizes the page from the image resolution, matched to the nearest standard paper size; when off, one image pixel becomes one point. |
custom_page_width / custom_page_height | 0 | Image input only: exact page width and height in points (1 pt = 1/72 inch); both must be greater than 0. Takes precedence over enable_auto_page_size. |
Example:
ConvertOptions opt;
opt.excel_worksheet_option = ExcelWorksheetOption::e_ForPage;
opt.excel_all_content = true;
std::snprintf(opt.page_ranges, sizeof(opt.page_ranges), "%s", "1-3");
CPDFConversion::StartPDFToExcel("input.pdf", "password", "path/output.xlsx", opt);When converting PDF files to Excel files, you need to pay attention to the settings of the following options, which will directly affect the content written to the Excel file.
Content options: If you set the excel_all_content option, The converted Xlsx file will contain all the contents in the PDF.
Worksheet options:
| Option | Description |
|---|---|
ExcelWorksheetOption::e_ForTable | Create one sheet for one table. |
ExcelWorksheetOption::e_ForPage | Create one sheet for one PDF page. |
ExcelWorksheetOption::e_ForDocument | Create one sheet for the entire PDF document. |
This sample demonstrates how to convert from a PDF to XLSX file.
ConvertOptions opt;
CPDFConversion::StartPDFToExcel("excel.pdf", "password", "path/output.xlsx", opt);
// Set all content options.
opt.excel_all_content = true;
opt.excel_worksheet_option = ExcelWorksheetOption::e_ForDocument;
CPDFConversion::StartPDFToExcel("excel.pdf", "password", "path/output.xlsx", opt);