Possible Duplicate:
how to fit pdf page in entire view
我毫无问题地显示了 PDF,但是,原始 PDF 在我编译应用程序时没有显示大边距。我的代码:
在 H 文件中:
@interface viewPDF : UIView
{
CGPDFDocumentRef document;
}
在M文件中:
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:(CGRect)frame];
if (self) {
self.backgroundColor = [UIColor clearColor];
NSString *pathToPdfDoc = [[NSBundle mainBundle] pathForResource:@"myPDF" ofType:@"pdf"];
NSURL *pdfUrl = [NSURL fileURLWithPath:pathToPdfDoc];
document = CGPDFDocumentCreateWithURL((__bridge CFURLRef)pdfUrl);
currentPage = 1;
}
return self;
}
-(void)drawRect:(CGRect)inRect{
if(document)
{
CGPDFPageRef page = CGPDFDocumentGetPage(document, currentPage);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSaveGState(ctx);
CGContextTranslateCTM(ctx, 0.0, [self bounds].size.height);
CGContextScaleCTM(ctx, 1.0, -1.0);
CGContextConcatCTM(ctx, CGPDFPageGetDrawingTransform(page, kCGPDFCropBox, [self bounds], 0, true));
CGContextDrawPDFPage(ctx, page);
CGContextRestoreGState(ctx);
}
有任何优秀的 PDF 开发人员知道如何避免边距吗?
最佳答案
PDF 页面由 2 个框定义:定义物理页面大小的媒体框和定义媒体框内页面的可见区域的裁剪框。您需要做的是在绘制PDF页面之前设置与裁剪框匹配的剪切路径。然后,当您绘制页面时,裁剪框之外的所有内容都将被剪掉,您将看到该页面,就像您在任何查看器中看到的一样。
关于ios - 在 iOS 中,使用 CGPDFDocumentRef,为什么我的 PDF 显示大边距而不是整个页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11641068/