views:

45

answers:

2

An iPhone app which I am creating generates reports from a Core Data database as a CSV file, which can then be emailed so that the user may use that data elsewhere outside of the app. I would also like to offer the ability to generate the same reports as a PDF file (of course, with nicer formatting) allowing the user to immediately print the report rather than having to jump through several hoops as with the CSV file - i.e. open in another application (e.g. Excel, Numbers) then reformat the columns (so they are wide enough for printing), bold the headings, etc.

Essentially, I want to provide the PDF file so that the user is immediately given a nicely formatted report, and they only need to export the CSV file if they wish to do data manipulation and need a format which is editable.

I was thinking that the easiest method would be taking the CSV file and the converting this into a PDF file, which would be the same as the CSV except would incorporate nicer formatting (such as a tabular layout) rather than the simple comma-separated format of the CSV file. I have been unable to find any ready-made classes for this purpose (to avoid reinventing the wheel) and I am unsure how to approach this since I have limited experience with this aspect of the SDK. Any suggestions or pointers in the right direction would be much appreciated.

A: 

You have two different problems:

  1. Read CSV data into some structure in memory
  2. Turn some structure in memory into a PDF

Aaron Saunders has posted some links for step 2, so here's a link for step 1:

http://github.com/davedelong/CHCSVParser

That's a CSV parser I wrote that will turn your CSV file into an NSArray of NSArrays of NSStrings.

Dave DeLong