0

PDFドキュメントを表示するアプリの構築を始めたばかりです。私は、実験、UIView のサブクラス化、および Apples デモのコードの使用を行ってきました。131 ppi で 1024 x 748 ピクセルの画像を含む PDF ドキュメントがあるので、iPad の画面を横向きに表示する必要があります。

アプリを実行すると、PDF はフル サイズの約 0.25% に縮小され、iPad 画面の中央に配置されます。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);

}
4

1 に答える 1

1

答えは簡単でした。PDF の画像の ppi を 72 ppi (1024 x 748 のまま) に変更しました。正しく画面いっぱいに表示されるようになりました。iPad のピクセル密度に合わせる必要があると思っていましたが、そうではないようです。

JK

于 2010-08-26T00:00:40.190 に答える