I have been working on the same task since 2 days, but no result I need your help. Below is the issue,
I am storing the user health details in sqlite3 DB and retrieving back in a string (total 8 values I am appending in one string), then I am trying to save the appended string as PDF file in document directory below is my code
NSArray *pdf = [NSArray arraywithobject:pdf_val];
//pdf_val is the appended string with 8 values in it.
NSArray *documentPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *saveDirectory = [documentPath objectAtIndex:0];
NSString *saveFileName = @"mypdf.pdf";
NSString *finalPath = [saveDirectory stringByAppendingPathComponent:saveFileName];
[pdfwriteToFile:finalpath atomically:YES];
After processing the above code I am trying to load the PDF file in the UIWebView, but I am get an error: failed to load pdf: '%PDF' not found and sometimes it shows empty webView.
You’re not writing a PDF to
mypdf.pdf. You’re writing a binary property list, which contains an array, which contains whatever is in yourpdf_valvariable.What is in
pdf_val? If that is a PDF, then you need to just write it tomypdf.pdfdirectly, without wrapping it in anNSArray. Perhapspdf_valis anNSDatacontaining the PDF, in which case you can send it thewriteToFile:atomically:message. If it’s not anNSDatacontaining the PDF, then what is it?If
pdf_valis the string containing your eight concatenated values, then you need to learn how to create a PDF. Creating a PDF is explained in the Drawing and Printing Guide for iOS.