Skip to content
Guides

Convert PDF to Excel

Overview

ComPDFKit 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.

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 worksheetOptions option, only the text content will be written to the Excel file (without containing the table content).

  • Worksheet options:

OptionsDescription
CPDFConvertExcelWorksheetForEachTableCreate one sheet for one table.
CPDFConvertExcelWorksheetForEachPageCreate one sheet for one PDF page.
CPDFConvertExcelWorksheetForTheDocumentCreate one sheet for the entire PDF document.

Notice

  • In order to get better conversion effects, it is recommended to enable OCR or layout analysis.
  • When you enable the OCR feature, the isContainOCRBgImageoption will be invalid.

Sample

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

objective-c
// Get the path of the PDF file.
NSString *pdfPath = @"...";
// Get the path to the Excel file.
NSString *outputPath = @"...";

CPDFConvertExcelOptions *options = [[CPDFConvertExcelOptions alloc] init];
[options setContentOptions:CPDFConvertExcelContentAllContent];
[options setWorksheetOptions:CPDFConvertExcelWorksheetForEachPage];
// Set the OCR language, which takes effect only when IsAllowOCR is true.
[options setIsAllowOCR:YES];
// Whether to contain images when converting,which takes effect only when IsAllowOCR is false.
[options setIsContainImages:NO];
// Set whether to contain background images, which takes effect only when IsAllowOCR is true. 
[options setIsContainOCRBgImage:NO];
// Whether to contain annotations when converting.
[options setIsContainAnnotations:NO];
// OCR language is English.
[options setLanguage:COCRLanguageEnglish];

CPDFConverterExcel *converter = [[CPDFConverterExcel alloc] initWithURL:[NSURL fileURLWithPath:pdfPath] password:nil];
[converter convertToFilePath:outputPath pageIndexs:nil options:options];