我正在尝试以pdf格式保存一些NSData。 NSData来自下载的pdf。这就是我尝试这样做的方式:
NSData* data = [DKStoreManager loadFileWithName:_FileName forFolderNumber:[_FolderNumber intValue] forUser:userID andType:_FolderType];
NSDictionary *myDictionary = (NSDictionary*) [NSKeyedUnarchiver unarchiveObjectWithData:data];
NSData* dataFile;
NSMutableDictionary* dict = [myDictionary objectForKey:@"MultiFileOtherFile2"];
dataFile = [dict objectForKey:@"FileData"];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *pdfPath = [documentsDirectory stringByAppendingPathComponent:@"mLocalFileName.pdf"];
[dataFile writeToFile:pdfPath atomically:YES];
NSString *phrase = nil; // Document password (for unlocking most encrypted PDF files)
ReaderDocument *document = [ReaderDocument withDocumentFilePath:pdfPath password:phrase];
这不起作用。唯一有效的是:
NSArray *pdfs = [[NSBundle mainBundle] pathsForResourcesOfType:@"pdf" inDirectory:nil];
NSString *filePath = [pdfs lastObject]; assert(filePath != nil); // Path to last PDF file
ReaderDocument *document = [ReaderDocument withDocumentFilePath:filePath password:phrase];
...手动将PDF添加到Xcode !!我甚至尝试了所有的转换解决方案:
How to convert a NSData to pdf in iPhone sdk?
......没有人工作!
提前感谢您的帮助。
答案 0 :(得分:0)
您的问题不在这些代码行中。你的问题是:
ReaderDocument
,用于打开文件的类,有错误并且文件下载不正确也许PDF文件使用了ReaderDocument
课程不支持的一些PDF功能? PDF格式非常广泛。