1

我正在尝试渲染 pdf 文档的页面。在 Adob​​e Reader 中打开 pdf 可以正确显示页面。当我尝试将其渲染到视图中时,我会在屏幕边缘看到额外的“项目”。它们看起来像指南和页面创建日期。我已经尝试使用所有 PDFBox 选项,但我无法找到正确的选项。我正在使用 TiledPDFView 类来呈现页面。它使用CATiledLayer类。以下是相关方法。

-(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);
}

我真的不确定如何删除这些准则。这可能只是我的界限问题。

图片!

4

1 回答 1

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);
}
于 2013-02-11T16:54:15.510 回答