2

I have to load a timesheet file in to an ipad app, which is in pdf or xls format. After loading these files(xls/pdf), I need to edit the values in timesheet file and save it. I could load these files in a UIWebView, but i couldn't edit these files. I need to know, how to make these files(xls/pdf) editable? Another question is that I need to convert the pdf file to xls format and xls file to pdf format from inside an ipad app. I hope this is pretty clear.

dgw
  • 13,418
  • 11
  • 56
  • 54
sree_iphonedev
  • 3,514
  • 6
  • 31
  • 50

1 Answers1

1

You should read PDF file using Quartz APIs and present it in your own view if you want to support editing. See below links

Is it possible to combine multiple pdf files into a single pdf file programmatically in iphone?

PDF editing with iPhone sdk

http://www.iphonedevsdk.com/forum/iphone-sdk-tutorials/10989-pdf-creation-tutorial.html

The idea is if you just want text editing, read and draw your pdf file using quartz 2D APIs, show all text objects inside pdf in editable text elements, let user change and and on save create/replace text objects in original pdf using Quartz 2D.

I got this code to draw a text string in pdf file

// Create URL for PDF file
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *filename = @"test.pdf";
NSURL *fileURL = [NSURL fileURLWithPathComponents:[NSArray arrayWithObjects:documentsDirectory, filename, nil]];

// Create PDF context
CGContextRef pdfContext = CGPDFContextCreateWithURL((CFURLRef)fileURL, NULL, NULL);
CGPDFContextBeginPage(pdfContext, NULL);
UIGraphicsPushContext(pdfContext);

// Flip coordinate system
CGRect bounds = CGContextGetClipBoundingBox(pdfContext);
CGContextScaleCTM(pdfContext, 1.0, -1.0);
CGContextTranslateCTM(pdfContext, 0.0, -bounds.size.height);

// Drawing commands
[@"Hello World!" drawAtPoint:CGPointMake(100, 100) withFont:[UIFont boldSystemFontOfSize:72.0f]];

// Clean up
UIGraphicsPopContext();
CGPDFContextEndPage(pdfContext);
CGPDFContextClose(pdfContext);
Community
  • 1
  • 1
msk
  • 8,885
  • 6
  • 41
  • 72
  • Thank you very much MSK for your fast reply. I will try to do it as you told me and let you know the status. I think the links you included is really i needed. Once again thank you very much. I was in research of this topic for the last 1 week. One more solution I need to find, loading and editing xls file in iOS. Also converting pdf to xls and xls to pdf format.If conversion is not possible within iOS, is it possible with the help of server side.Thanks and regards, Sree. – sree_iphonedev Mar 31 '12 at 09:03
  • You need to search for xls read/writing libs for ios. I am not aware of any. Check out http://www.iphonedevsdk.com/forum/iphone-sdk-development/48825-how-read-data-excel-docs-xls.html I am sure writing your own (or porting some existing) would not be a big task. You can port http://www.libxl.com also. – msk Mar 31 '12 at 11:41
  • Hi MSK, Do you have any idea about parsing PDF data. I need to get the data inside the PDF. I searched on google, but I didn't find any useful links. – sree_iphonedev Apr 12 '12 at 06:53
  • Read Quartz APIs. They have full support for reading/writing PDF files. – msk Apr 12 '12 at 12:22