2013-02-09 23 views
1

我试图渲染PDF文档的页面。在Adobe Reader中打开pdf可以正确显示页面。当我尝试将其渲染到视图中时,我会在屏幕边缘获得更多“项目”。它们看起来像指引线和页面创建日期。我试过使用所有的PDFBox选项,但我一直没能找到正确的选项。我正在使用TiledPDFView类来呈现页面。它使用CATiledLayer类。以下是相关的方法。渲染PDF页面显示页面边缘的指南和日期

-(void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx 
{ 
    CGContextSetRGBFillColor(ctx, 1.0,1.0,1.0,1.0); 
    CGContextFillRect(ctx, self.bounds); 
    CGContextSaveGState(ctx); 
    CGContextTranslateCTM(ctx, 0.0, self.bounds.size.height); 
    CGContextScaleCTM(ctx, 1.0, -1.0); 
    //I've tried many options in the PDFBox parameter. 
    CGContextConcatCTM(ctx, CGPDFPageGetDrawingTransform(pdfPage, kCGPDFCropBox, self.bounds, 0, false)); 
    CGContextDrawPDFPage(ctx, pdfPage); 
    CGContextRestoreGState(ctx); 
} 

我真的不确定如何删除这些指南。这可能只是我的边界问题。

The Image!

回答

1

我能够通过不使用CGPDFPageGetDrawingTransform方法,只是在做转变自己解决这个问题。我发现了一些代码,我将在此分享以供将来参考。我不记得我从哪里得到的代码:(。

-(void)drawRect:(CGRect)rect 
{ 
    CGContextRef context = UIGraphicsGetCurrentContext(); 
    CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor); 
    CGContextFillRect(context, rect); 
    CGContextGetCTM(context); 
    CGContextScaleCTM(context,1,-1); 
    CGContextTranslateCTM(context, 0, -rect.size.height); 
    CGRect mediaRect = CGPDFPageGetBoxRect(pdfPage, kCGPDFCropBox); 
    CGContextScaleCTM(context, rect.size.width/mediaRect.size.width, rect.size.height/mediaRect.size.height); 
    CGContextTranslateCTM(context, -mediaRect.origin.x, -mediaRect.origin.y); 
    CGContextDrawPDFPage(context, pdfPage); 
}