2011-10-05 83 views

回答

0

解決方案是爲圖像創建圖形上下文並在該上下文中呈現PDF頁面。當你創建你的上下文時,你可以指定所需的分辨率 此代碼將做的工作:

+ (UIImage *) convertPDFPageToImage: (CGPDFPageRef) page withResolution: (float) resolution { 
    CGRect cropBox = CGPDFPageGetBoxRect(page, kCGPDFCropBox); 
    int pageRotation = CGPDFPageGetRotationAngle(page); 

    if ((pageRotation == 0) || (pageRotation == 180) ||(pageRotation == -180)) { 
     UIGraphicsBeginImageContextWithOptions(cropBox.size, NO, resolution/72); 
    } 
    else { 
     UIGraphicsBeginImageContextWithOptions(CGSizeMake(cropBox.size.height, cropBox.size.width), NO, resolution/72); 
    } 

    CGContextRef imageContext = UIGraphicsGetCurrentContext(); 

    [PDFPageRenderer renderPage:page inContext:imageContext]; 

    UIImage *pageImage = UIGraphicsGetImageFromCurrentImageContext(); 

    UIGraphicsEndImageContext(); 

    return pageImage; 
} 

從這裏取:http://ipdfdev.com/2011/03/28/convert-a-pdf-page-to-image-on-the-iphone-and-ipad/

+2

此代碼引用的UIKit爲可可觸摸,不會了AppKit可可,作爲要求。 – colincameron