2012-02-25 3 views

답변

0

당신이 한 페이지에 이미지가이

UIImage *currentPage = [UIImage drawCurrentView:currentPageNum]; 

이있는 drawCurrentView 사용할 수 원하는 경우 :

+(UIImage*)drawCurrentView:(NSUInteger)currentPageNum 
{ 

NSString *filePath = //Your PDF Path 

CGSize resultImageSize = CGSizeMake(320, 480);//For iPhone 

CFStringRef pathRef = CFStringCreateWithCString (NULL, [filePath UTF8String], 
               kCFStringEncodingUTF8); 
CFURLRef pdfURL = CFURLCreateWithFileSystemPath (NULL, pathRef, 
               kCFURLPOSIXPathStyle, 0); 
CFRelease(pathRef); 
CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL(pdfURL); 

CFRelease(pdfURL); 
CGPDFPageRef myPageRef = CGPDFDocumentGetPage(pdf,currentPageNum); 

// get the rect of our page 
CGRect pageRect = CGPDFPageGetBoxRect(myPageRef, kCGPDFCropBox); 

// create a new context for resulting image of my desidered size 
UIGraphicsBeginImageContext(resultImageSize); 
CGContextRef ctx = UIGraphicsGetCurrentContext(); 
CGContextSaveGState(ctx); 
CGContextScaleCTM(ctx, 1, -1); 

// translate so the origin is offset by exactly the rect origin 
CGContextTranslateCTM(ctx, 0, -resultImageSize.height); 
CGContextScaleCTM(ctx, resultImageSize.width /pageRect.size.width,resultImageSize.height/ pageRect.size.height); 

// now draw the document 
CGContextDrawPDFPage(ctx, myPageRef); 
CGContextRestoreGState(ctx); 

// generate image 
UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 
CGPDFDocumentRelease(pdf); 

return resultingImage; 
} 
+0

drawCurrentView 무엇입니까? UIImage에 대한 방법은 없습니다. – fulberto100

+0

오, 미안 해요 @ fulberto100 전 모든 코드를 통과하지 못했습니다 .. 내 편집을 확인하십시오. –

관련 문제