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 CSV ​

Overview ​

ComPDF Conversion SDK supports converting PDF documents to CSV (Comma-Separated Values). Converting PDF to CSV is a common need, usually used to extract tabular or structured data from PDF documents and convert them into CSV files.

Conversion Options ​

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

OptionDefaultMeaning
CsvFormatfalseMust be on to output CSV. Only tables are exported.
WorksheetOptionExcelWorksheetOption.e_ForTableExcelWorksheetOption.e_ForTable: one CSV file per table; ExcelWorksheetOption.e_ForPage: one CSV file per page; ExcelWorksheetOption.e_ForDocument: one CSV file with all tables, written to the output path.
AutoCreateFoldertrueWith ExcelWorksheetOption.e_ForTable or ExcelWorksheetOption.e_ForPage, when the output path is an existing folder, the CSV files are put in a new subfolder named after the input file; when off, they are written directly into that folder. If the output path is not an existing folder, a folder is created at that path.
EnableAiLayouttrueFinds tables (including tables without borders) with AI layout analysis; when off, only tables with ruling lines are found. 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.
EnableOCRfalseRecognizes text with OCR on the pages chosen by OcrOption. Required for image input; without it the conversion returns ErrorCode.e_ErrUnsupportedFeature. 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.
OutputDocumentPerPagefalseRuns a separate CSV export for each page; each export still follows WorksheetOption.
PageRangesEmptyPages to convert, e.g. "1-3,5,7-9"; empty converts every page. For multi-frame image input it selects the frames.

Example:

c#
ExcelOptions csvOptions = new ExcelOptions();
csvOptions.CsvFormat = true;
csvOptions.WorksheetOption = ExcelWorksheetOption.e_ForTable;
csvOptions.AutoCreateFolder = false;
ErrorCode error = CPDFConversion.StartPDFToExcel("input.pdf", "password", "path/output_folder", csvOptions);

Set Whether to Automatically Create Folders ​

When multiple CSV files may be output, you can control whether to automatically create folders to store the CSV files by setting the AutoCreateFolder option. When this option is enabled, a folder with the same name as the output file will be automatically created in the output path to store the CSV files.

Sample ​

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

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