由于iOS未命中PDFKit.framework,我认为UIImage受限的/破坏的PDF支持问题在于它不应该首先得到任何支持,在这方面,我报告了对它的有限支持有一个bug(rdar:8338627),这也是IB的一个bug,因为渲染支持很可能由osx继承。
我已经解决,只是手动渲染PDF在上下文然后保存,为一个UIImage的代码,低于
#include <dlfcn.h>
-(UIImage *)UIImageFromPDF:(NSString*)fileName size:(CGSize)size{
CFURLRef pdfURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), (CFStringRef)fileName, NULL, NULL);
if (pdfURL) {
CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL(pdfURL);
CFRelease(pdfURL);
//create context with scaling 0.0 as to get the main screen's if iOS4+
if (dlsym(RTLD_DEFAULT,"UIGraphicsBeginImageContextWithOptions") == NULL) {
UIGraphicsBeginImageContext(size);
}else {
UIGraphicsBeginImageContextWithOptions(size,NO,0.0);
}
CGContextRef context = UIGraphicsGetCurrentContext();
//translate the content
CGContextTranslateCTM(context, 0.0, size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextSaveGState(context);
//scale to our desired size
CGPDFPageRef page = CGPDFDocumentGetPage(pdf, 1);
CGAffineTransform pdfTransform = CGPDFPageGetDrawingTransform(page, kCGPDFCropBox, CGRectMake(0, 0, size.width, size.height), 0, true);
CGContextConcatCTM(context, pdfTransform);
CGContextDrawPDFPage(context, page);
CGContextRestoreGState(context);
//return autoreleased UIImage
UIImage *ret = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CGPDFDocumentRelease(pdf);
return ret;
}else {
NSLog(@"Could not load %@",fileName);
}
return nil;
}