在iOS中,使用CGPDFDocumentRef,为什么是显示大的利润,而不是整个页面我的PDF?

2019-09-20 03:18发布

可能重复:
如何适应整个视图PDF页面

我没有问题呈现出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开发商知道如何避免利润率?

Answer 1:

媒体盒,其定义了物理页面大小和它定义了媒体盒内的页面的可视区域内的裁切框:该PDF页面由2盒定义。 什么,你需要做的是设置绘制PDF页面之前相匹配的裁剪框剪切路径。 然后,当你绘制裁剪框外的页面都将被裁减掉,你会看到页面为你在任何浏览器看到它。



文章来源: In iOS, using CGPDFDocumentRef, why is my PDF showing big margins and not the whole page? [duplicate]