我有一個pdf,其中的內容來自web服務檢索到的NSData。我試圖將這些數據保存爲設備照片庫中的pdf。是否有可能將它作爲pdf存儲在手機庫中,或者我必須將其轉換爲圖像並保存它?將NSData存儲到iphone手機庫
謝謝。
我有一個pdf,其中的內容來自web服務檢索到的NSData。我試圖將這些數據保存爲設備照片庫中的pdf。是否有可能將它作爲pdf存儲在手機庫中,或者我必須將其轉換爲圖像並保存它?將NSData存儲到iphone手機庫
謝謝。
UIGraphicsBeginImageContext(viewFrame1.frame.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
要檢索的庫路徑:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *libraryDirectory = [paths objectAtIndex:0];
responseData是你必須與PDF信息NSData對象。這將在應用程序庫文件夾中將pdf保存爲「mypdffile.pdf」。
[responseData writeToFile:[libraryDirectory stringByAppendingPathComponent:@"mypdffile.pdf"] atomically:YES];
我發現此頁非常有用。 Working with Files in Objective-C
是的,它寫道,但Preview.app無法打開以這種方式保存的文件。任何幫助? – Meet 2013-09-25 05:45:49
hayden,謝謝你的回答。我注意到登陸PDF的唯一方法是將其作爲我相信的圖像來保護它。 – kforkarim 2012-01-19 16:12:45