我通过创建一个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