2011-08-03 33 views
3

我寫了一個視圖渲染PDF頁面:如何使用更高分辨率繪製PDF到CGContext?

-(UIPDFRenderView*) initWithFrame:(CGRect)frame withDocument:(CGPDFDocumentRef*)document withPageNumber:(int)pageNumber 
{   
    if (self) 
    { 
     page = CGPDFDocumentGetPage (*document, pageNumber); 

     pageRect = CGPDFPageGetBoxRect(page, kCGPDFMediaBox); 
     pdfScale = (CGRectGetWidth(frame)/pageRect.size.width); 

     rect = frame; 
     self = [super initWithFrame:CGRectMake(CGRectGetMinX(frame), 
               CGRectGetMinY(frame), 
               CGRectGetWidth(frame), 
               CGRectGetHeight(pageRect) * pdfScale)]; 
    } 
    return self; 
} 


-(void) drawRect:(CGRect)rect 
{ 
    [self displayPDFPageWithContext:UIGraphicsGetCurrentContext()];  
} 

-(void) displayPDFPageWithContext:(CGContextRef)context 
{ 
    CGContextSetRGBFillColor(context, 1.0,1.0,1.0,1.0); 
    CGContextFillRect(context, self.bounds); 

    CGContextSaveGState(context); 
    CGContextTranslateCTM(context, 0.0, self.bounds.size.height); 
    CGContextScaleCTM(context, pdfScale,-1*pdfScale); 

    CGContextDrawPDFPage (context, page); 
} 

我使用視圖PDF文檔的每一頁中的一個,並將其添加到acrollview。 問題是如果我放大,頁面是pixelig。沒有意外,因爲我正在使用屏幕上下文來呈現PDF。是否有任何可能性使用雙精度分辨率渲染該PDF以使縮放比例達到2倍?

回答

1

好吧,我得到了解決方案,我將它渲染爲原始大小,並啓動scrollview,使得pdf的寬度適合scrollview的寬度。用這種方法,我可以縮放到原始大小(1的比例)。