Tutorials

Convert PDF to CSV in Objective-C, Kotlin, and C#

By ComPDFKit | Fri. 17 May. 2024
Conversion

CSV is one of the most popular file formats when it comes to storing tabular data. If you want to manipulate or analyze data in PDF documents, you can convert PDF to CSV format, storing information in the form of tabular rows and columns.

 

 

What Is CSV

 

A Comma Separated Values (CSV) file is a plain text file, containing a list of data. And they may sometimes be referred to as Character Separated Values or Comma Delimited files. They mostly use the comma character to separate or delimit data, but sometimes use other characters like semicolons. You can infer these meanings from the filename.

 

Since multiple applications can recognize records separated by comma, it’s very convenient to import CSV files. That’s why CSV files are commonly used for exchanging data between different applications, especially when there is a great deal of data to be sent. CSV files can be opened by a wide variety of programs, including Microsoft Excel, Google Sheets, Notepad, etc.



What ComPDFKit Offers

 

ComPDFKit is a product that offers software development kits (SDKs) and application programming interfaces (APIs) for our clients. So they can integrate the "PDF to CSV" feature into their website to boost productivity and provide the best way to process and analyze data efficiently. 


We offer a free online conversion tool that allows our customers to see how robust our SDK and API are. And, it's open and free for all people to try and convert PDF files to CSV format online without having to install any software like Adobe. Even if you want to convert PDF to CSV in your internal systems or apps, ComPDFKit SDK and API could meet your needs and be deployed into any system/device.

 

 

CSV vs Excel

 

When it comes to data, we usually think of Excel. What CSV and Excel have in common is that they both help store data in tabular format. And there are lots of differences between them. Let’s have a deeper look at the differences.

 

         - Performance: CSV files are just text files, they store data but do not contain formatting, formulas, macros, etc. The data in Excel files can be calculated and you can access formulas, macros, etc.

        - Memory: Importing CSV files can be much faster, and it also consumes less memory. Excel files consume more memory when importing data.

         - Storage Format: CSV files cannot store the data in charts or graphs format, while Excel files can do that.

        - Supported Platforms: CSV files can be opened with any text editor in Windows, while Excel files only can be opened with Microsoft Excel.

        - External Data: You cannot connect the CSV files to external data sources to fetch the data, like local workbooks, databases, web, etc. While Excel files can do that. 

 

 

Convert PDF to CSV

 

ComPDFKit supports extracting only tables from PDF accurately and converting them to CSV, and one table is converted to one CSV file.

 

Objective-C

// Get the path of the PDF file.
NSString *pdfPath = @"...";
// Get the path to the PPT file.
NSString *outputPath = @"...";

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

 

Kotlin

val cPDFConvert = CPDFConverterCsv(context, uri, "")
val params = CPDFConvertCsvOptions()
val result: ConvertError = cPDFConvert.convert(outputDir, outputfilename, params, pageArrays, 
onHandle = onHandleCal, 
onProgress = onProgressCal, 
onPost = onPostCal)

 

C#

string resPath = "***";
string inputFilePath = "***";
string outputFolderPath = "***";
string outputFileName = "***";

CPDFConverter.Init(resPath);
CPDFConverterCsv converter = new CPDFConverterCsv(inputFilePath);

int pageCount = converter.GetPagesCount();
int[] pageArray = new int[pageCount];
for (int i = 0; i < pageArray.Length; i++)
{
    pageArray[i] = i + 1;
}

CPDFConverterError error = CPDFConverterError.C_UNKNOWN;
converter.Convert(outputFolderPath,ref outputFileName, pageArray, ref error, getPorgress);

 

 

Conclusion

 

In this blog, we introduced a new file format — CSV. Hope you have a clear understanding after reading the blog. And you can contact us to get a free trial of converting PDF to CSV.