我刚刚开始建立一个应用程序,将显示PDF文档。我一直在实验,继承UIView并使用苹果演示中的代码。我有一个PDF文档,其中包含一个1024x748像素的图像,分辨率为131ppi,因此它应该在横向视图中填充iPad屏幕。
当我运行这个应用程序时,pdf在iPad屏幕上居中缩放到其完整大小的大约.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);
}发布于 2010-08-26 08:00:40
答案很简单。将PDF中图像的ppi更改为72 ppi (仍为1024 x 748)。现在它正确地填满了屏幕。我认为我需要匹配iPads像素密度,但我猜不是。
Jk
https://stackoverflow.com/questions/3552119
复制相似问题