Create PDF from CSV on iPhone

The iPhone application that I create generates reports from the Core Data database as a CSV file, which can then be emailed so that the user can use this data elsewhere outside the application. I would also like to offer the opportunity to generate the same reports as a PDF file (of course, with better formatting), allowing the user to immediately print the report, instead of skipping through several hoops like with a CSV file, i.e. open in another application (e.g. Excel, Numbers), then reformat the columns (so that they are wide enough for printing), bold headings, etc.

In fact, I want to provide a PDF file so that the user immediately gets a report with a well-formatted file, and they need to export the CSV file if they want to do data manipulation and need an editable format.

I thought the easiest way is to take the CSV file and convert it to a PDF file, which will be the same as the CSV, except that it will contain more convenient formatting (for example, a tabular layout), and not just a comma-separated CSV file format. I could not find ready-made classes for this purpose (so as not to reinvent the wheel), and I'm not sure how to do this, since I have limited experience in this aspect of the SDK. Any suggestions or pointers in the right direction would be appreciated.

+5
source share
1 answer

You have two different problems:

  • Read CSV data in some structure in memory
  • Turn some structure in memory into PDF

Aaron Saunders posted some links for step 2, so here is the link for step 1:

http://github.com/davedelong/CHCSVParser

What wrote CSV parser, turn your CSV file in the NSArrayfrom NSArraysof NSStrings.

+1
source

All Articles