2010-08-23 8 views
0

PDF 문서를 표시하는 앱을 작성하기 시작했습니다. 나는 UIView를 서브 클래스 화하고 Apples 데모의 코드를 사용하여 실험을 해왔다. 1024 x 748 픽셀 (131 ppi)의 이미지가 포함 된 PDF 문서가 있으므로 iPad 화면을 가로보기로 채워야합니다.CGPDFDocument 배율

앱을 실행할 때 pdf는 iPad 화면 중앙에 전체 크기의 약 0.25 %로 조정됩니다. PDF가 전체 크기로 표시되지 않는 이유는 무엇입니까? 내 사용자 지정 UIView의에서

코드 :

-(id)initWithFrame:(CGRect)frame PDFName:(NSString *)pdfName 
{ 
    self = [super initWithFrame:frame]; 
    if(self != nil) 
    { 
     self.backgroundColor = [UIColor blueColor]; 
     self.opaque = YES; 
     self.clearsContextBeforeDrawing = YES; 

     CFURLRef pdfURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), (CFStringRef)pdfName, NULL, NULL); 
     pdf = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL); 
     CFRelease(pdfURL); 
    } 

    return self; 
} 


- (void)drawRect:(CGRect)rect { 

    // PDF page drawing expects a Lower-Left coordinate system, so we flip the coordinate system 
    // before we start drawing. 
    CGContextRef context = UIGraphicsGetCurrentContext(); 
    CGContextTranslateCTM(context, 0.0, self.bounds.size.height); 
    CGContextScaleCTM(context, 1.0, -1.0); 

    // Grab the first PDF page 
    CGPDFPageRef page = CGPDFDocumentGetPage(pdf, 1); 

    // We're about to modify the context CTM to draw the PDF page where we want it, so save the graphics state in case we want to do more drawing 
    CGContextSaveGState(context); 
    // CGPDFPageGetDrawingTransform provides an easy way to get the transform for a PDF page. It will scale down to fit, including any 
    // base rotations necessary to display the PDF page correctly. 
    CGAffineTransform pdfTransform = CGPDFPageGetDrawingTransform(page, kCGPDFMediaBox, self.bounds, 0, true); 
    // And apply the transform. 
    CGContextConcatCTM(context, pdfTransform); 
    // Finally, we draw the page and restore the graphics state for further manipulations! 
    CGContextDrawPDFPage(context, page); 
    CGContextRestoreGState(context); 

} 

답변

1

대답은 간단했다. PDF의 이미지 ppi를 72ppi (여전히 1024 x 748)로 변경했습니다. 이제 화면이 올바르게 채워집니다. 나는 iPads 픽셀 밀도를 일치시킬 필요가 있다고 생각했지만, 그렇게 생각하지는 않습니다.

jk

+0

PPI는 아무 관련이 없습니다. 가능성은 귀하의 초기 PDF 해상도는 612 × 792의 일반적인 경계 상자였습니다. 이미지의 경계선을 변경하면 PDF에 대한 문제가 해결되지만 PDF 변형의 값을 변경하거나 PDF보기를 늘리거나 확장 할 때 실질적인 해결책이됩니다. 또는 수퍼 뷰. – J2theC

관련 문제