首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CGPDFDocument缩放

CGPDFDocument缩放
EN

Stack Overflow用户
提问于 2010-08-24 06:13:43
回答 1查看 945关注 0票数 0

我刚刚开始建立一个应用程序,将显示PDF文档。我一直在实验,继承UIView并使用苹果演示中的代码。我有一个PDF文档,其中包含一个1024x748像素的图像,分辨率为131ppi,因此它应该在横向视图中填充iPad屏幕。

当我运行这个应用程序时,pdf在iPad屏幕上居中缩放到其完整大小的大约.25%。为什么PDF不是全尺寸显示的?

来自我的自定义UIView的代码:

代码语言:javascript
复制
-(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);

}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-08-26 08:00:40

答案很简单。将PDF中图像的ppi更改为72 ppi (仍为1024 x 748)。现在它正确地填满了屏幕。我认为我需要匹配iPads像素密度,但我猜不是。

Jk

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3552119

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档