由於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;
}