使用CGContextDrawPDFPage进行PDF渲染:找不到CropBox [英] PDF rendering using CGContextDrawPDFPage : cannot find CropBox

查看:641
本文介绍了使用CGContextDrawPDFPage进行PDF渲染:找不到CropBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要显示从Web服务收到的PDF文件的内容。

I need to display the content of PDF files that i receive from a Web Service.

我的问题是所有PDF框都返回相同的值。你知道我正在使用的文件有什么问题吗?

My problem is that all PDF boxes returns the same value. Do you have any idea what can be wrong with the files i'm using ?

CGPDFPageRef drawPDFPageRef = CGPDFPageRetain( CGPDFDocumentGetPage(pdf, 1) );
CGRect cropBoxRect = CGPDFPageGetBoxRect(drawPDFPageRef, kCGPDFCropBox);
CGRect mediaBoxRect = CGPDFPageGetBoxRect(drawPDFPageRef, kCGPDFMediaBox);

cropBoxRect =(0,0,595,842)
mediaBoxRect =(0,0,595,842)

cropBoxRect = (0,0,595,842) mediaBoxRect = (0,0,595,842)

当我在UIWebView中显示PDF时内容没问题

When i display the PDF in a UIWebView the content is ok

这是由UIWebView呈现的PDF

This is the PDF rendered by a UIWebView

这是由CGContextDrawPDFPage呈现的PDF

This is the PDF rendered by CGContextDrawPDFPage

感谢您的帮助,
Vincent

Thanks for your help, Vincent

推荐答案

这看起来不像元数据,而是像媒体框被用来裁剪PDF而不是裁剪框。在你的代码中你可能有这样的东西:

That doesn't look like metadata, but rather like the media box was being used to crop the PDF instead of the crop box. In your code you probably have something like this:

  CGContextSetInterpolationQuality(ctx, kCGInterpolationHigh); 
  CGContextSetRenderingIntent(ctx, kCGRenderingIntentDefault); 
  CGContextSetRGBFillColor( ctx, 1.0, 1.0, 1.0, 1.0 );
  CGContextFillRect( ctx, CGContextGetClipBoundingBox( ctx ));

  CGContextTranslateCTM( ctx, 0.0, self.bounds.size.height );
  CGContextScaleCTM( ctx, 1.0, -1.0 );
  CGAffineTransform pdfXfm = CGPDFPageGetDrawingTransform( pdfPage, kCGPDFMediaBox, self.bounds, 0, true );
  CGContextConcatCTM( ctx, pdfXfm );
  CGContextDrawPDFPage( ctx, pdfPage );

尝试在<$ c $中使用 kCGPDFCropBox c> CGPDFGetPageDrawingTransform ,这可能会有所帮助

Try using kCGPDFCropBox in CGPDFGetPageDrawingTransform, that could help

这篇关于使用CGContextDrawPDFPage进行PDF渲染:找不到CropBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆