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 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.
This format uses only the following options of ExcelOptions; the other options have no effect:
| Option | Default | Meaning |
|---|---|---|
CsvFormat | false | Must be on to output CSV. Only tables are exported. |
WorksheetOption | ExcelWorksheetOption.e_ForTable | ExcelWorksheetOption.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. |
AutoCreateFolder | true | With 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. |
EnableAiLayout | true | Finds 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. |
EnableAiTableRecognition | 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 (EnableAiLayout on). |
TableRecognitionAccuracy | 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. |
EnableOCR | false | Recognizes 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. |
OcrOption | 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 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. |
EnableDocumentOrientationClassification | false | Detects the page rotation and turns the page image upright before OCR. Only takes effect when EnableOCR is on. |
EnableDocumentDewarp | false | Flattens curved or warped page photos before OCR. Only takes effect when EnableOCR is on. |
OutputDocumentPerPage | false | Runs a separate CSV export for each page; each export still follows WorksheetOption. |
PageRanges | Empty | Pages to convert, e.g. "1-3,5,7-9"; empty converts every page. For multi-frame image input it selects the frames. |
Example:
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);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.
This sample demonstrates how to convert from a PDF to CSV file.
string inputFilePath = "***";
string password = "***";
string outputFileName = "***";
ExcelOptions excelOptions = new ExcelOptions();
excelOptions.CsvFormat = true;
ErrorCode error = CPDFConversion.StartPDFToExcel(inputFilePath, password, outputFileName, excelOptions);