How to Convert string-> pdf
i'm working with web services that returns a base64 string representing a pdf file.
I am able to decode that string into NSData but how to show th开发者_如何学Goat into pdf.
Is there any way to store that data as a .pdf file and show it in application.
Any ideas on how I can go about this? I have looked at a few posts and still can't seem to figure it out.
Any idea's appreciated, thanks :)
First you need to save the data into a file, then load it into a webview
- (void)DisplayPdf:(NSData *)pdfContent
{
NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask ,YES );
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *finalPath = [documentsDirectory stringByAppendingPathComponent:@"myPdf.pdf"];
NSURL *url = [NSURL fileURLWithPath:finalPath];
[pdfContent writeToURL:url atomically:YES];
[aWebView loadRequest:[NSURLRequest requestWithURL:url]];
}
精彩评论