iOS는 PDFKit.framework를 그리워합니다. UIImage의 제한된/깨진 PDF 지원 문제는 처음부터 아무런 지원도하지 않는다는 것입니다. 그 점에 관해서는 제한적인 지원을보고했습니다. 버그로 (rdar : 8338627) 그것은 IB에서 너무 버그를 렌더링 지원 아마도 osx에서 실시하고있다.
난 그냥 아래 인 코드하는 위해있는 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;
}