我通過創建一個PDF上下文並給它一個路徑渲染PDF定義如下:iphone PDF格式保存到文檔存儲
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *docsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *file = [docsDirectory stringByAppendingPathComponent:@"mypdf.pdf"];
,然後使用類似下面的這條道路:
char * fileutf8 = [file UTF8String];
CGContextRef pdfContext;
CFStringRef path;
CFURLRef url;
CFMutableDictionaryRef myDictionary = NULL;
path = CFStringCreateWithCString (NULL, fileutf8,kCFStringEncodingUTF8);
url = CFURLCreateWithFileSystemPath (NULL, path,kCFURLPOSIXPathStyle, 0);
CFRelease (path);
myDictionary = CFDictionaryCreateMutable(NULL, 0,&kCFTypeDictionaryKeyCallBacks,&kCFTypeDictionaryValueCallBacks);
CFDictionarySetValue(myDictionary, kCGPDFContextTitle, CFSTR("My PDF File"));
CFDictionarySetValue(myDictionary, kCGPDFContextCreator, CFSTR("My Name"));
pdfContext = CGPDFContextCreateWithURL (url, &size, myDictionary);
CFRelease(url);
CFRelease(myDictionary);// rendering code follows
長話短說我看不到PDF是否看起來不錯,因爲我沒有在iTunes的File Sharing區域找到它。我錯過了什麼嗎?
感謝隊友,UIFileSharingEnabled參數很有用。 – 2010-12-13 12:55:55