如何在缩放模式下使用CGPDFDocument绘制PDF?

时间:2017-07-13 11:30:12

标签: ios iphone pdf-generation core-graphics cgpdfdocument

我正在使用CGPDFDocument将pdf绘制到UIView屏幕中。 然而,在绘制pdf时我会遇到一些事情,所以你的帮助会受到赞赏。

要求:我希望我的pdf文档以一定的比例显示在UIView上,这样我的pdf文档很容易被用户读取,而无需放大或缩小。

正常流程:

//1. Set the frame of view
view.frame = CGRectMake(0,0,1008,612);

//2. Normal scale 
CGContextScaleCTM(context, 1.0, -1.0);

//3. Translate PDF
CGContextTranslateCTM(context, 0, -[self bounds].size.height);

现在,当我尝试使用因子1.2扩展pdf时,下面的内容值应该是什么:

//1. Set the frame of view
view.frame = CGRectMake(0,0,1008*1.2,612*1.2);

//2. here i am scaling the pdf with 1.2 scale factor
CGContextScaleCTM(context, 1.2, -1.2);

//3. Translate PDF, so what will be the value of below parameter according to scale factor 1.2?
CGContextTranslateCTM(context, ?, ?);

当我使用比例因子为1.2时,CGContextTranslateCTM的值是多少? 要么 有关CGContextTranslateCTM功能如何工作的人可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

试试这个:

//1. Set the frame of view
view.frame = CGRectMake(0,0,1008*1.2,612*1.2);

//2. Translate PDF to bottom left
CGContextTranslateCTM(context, 0, view.frame.height);

//3. Scale with 1.2 and reverse Y
CGContextScaleCTM(context, 1.2, -1.2);

这是一篇博客文章,详细解释了使用CoreGraphics渲染PDF页面时需要执行的操作:http://ipdfdev.com/2011/03/23/display-a-pdf-page-on-the-iphone-and-ipad/