Skip to content
DemoFAQ

PDF Generation Template Editor

Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.

View on GitHub

Convert PDF to Excel ​

Overview ​

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.

Conversion Options ​

This format uses only the following options of ExcelOptions; the other options have no effect:

OptionDefaultMeaning
CsvFormatfalseMust be off to output an .xlsx workbook; when on, CSV is output instead (see "PDF to CSV").
WorksheetOptionExcelWorksheetOption.e_ForTableExcelWorksheetOption.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.
AllContentfalseAlso writes the content outside tables (text, images, headers and footers); when off, only tables are kept. Ignored with ExcelWorksheetOption.e_ForTable.
EnableAiLayouttrueUses 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.
EnableAiTableRecognitiontrueRecognizes 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 (EnableAiLayout on).
TableRecognitionAccuracyTableRecognitionAccuracy.e_BalancedTable 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.
ContainImagetrueKeeps the images and vector graphics of the source. Only visible when content outside tables is written (AllContent on with ExcelWorksheetOption.e_ForPage or ExcelWorksheetOption.e_ForDocument); tables-only output never contains images.
ContainAnnotationtrueOutputs 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.
EnableOCRfalseRecognizes text with OCR on the pages chosen by OcrOption. Ignored if the license does not include OCR.
OcrOptionOCROption.e_AllWhich 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 EnableOCR is on.
Languages{ OCRLanguage.e_ENGLISH }OCR recognition languages; when no language is given, English is used. Only takes effect when EnableOCR is on.
EnableDocumentOrientationClassificationfalseDetects the page rotation and turns the page image upright before OCR. Only takes effect when EnableOCR is on.
EnableDocumentDewarpfalseFlattens curved or warped page photos before OCR. Only takes effect when EnableOCR is on.
FormulaToImagetrueOutputs 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.
FontNameEmptyUses 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.
OutputDocumentPerPagefalseWrites one workbook per page instead of one workbook.
PageRangesEmptyPages to convert, e.g. "1-3,5,7-9"; empty converts every page. For multi-frame image input it selects the frames.
EnableAutoPageSizefalseImage input only: sizes the page from the image resolution, matched to the nearest standard paper size; when off, one image pixel becomes one point.
CustomPageWidth / CustomPageHeight0Image input only: exact page width and height in points (1 pt = 1/72 inch); both must be greater than 0. Takes precedence over EnableAutoPageSize.

Example:

c#
ExcelOptions excelOptions = new ExcelOptions();
excelOptions.WorksheetOption = ExcelWorksheetOption.e_ForPage;
excelOptions.AllContent = true;
excelOptions.PageRanges = "1-3";
ErrorCode error = CPDFConversion.StartPDFToExcel("input.pdf", "password", "path/output.xlsx", excelOptions);

Set the content options for Excel ​

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 AllContent option, the converted XLSX file will contain all content in the PDF.

  • Worksheet options:

OptionDescription
ExcelWorksheetOption.e_ForTableCreate one sheet per table.
ExcelWorksheetOption.e_ForPageCreate one sheet per page.
ExcelWorksheetOption.e_ForDocumentCreate one sheet for the entire document.

Sample ​

This sample demonstrates how to convert from a PDF to XLSX file.

c#
string inputFilePath = "***";
string password = "***";
string outputFileName = "***";
ExcelOptions excelOptions = new ExcelOptions();
ErrorCode error = CPDFConversion.StartPDFToExcel(inputFilePath, password, outputFileName, excelOptions);