开发者

How to Convert string-> pdf

开发者 https://www.devze.com 2023-04-11 03:35 出处:网络
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.

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]];
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号