【问题标题】:How to draw PDF with CGPDFDocument in scaled mode?如何在缩放模式下使用 CGPDFDocument 绘制 PDF?
【发布时间】:2017-12-18 03:50:52
【问题描述】:

我正在使用 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 函数的工作原理吗?

【问题讨论】:

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


    【解决方案1】:

    试试这个:

    //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/

    【讨论】:

    • 感谢 iPDFDev 的快速回复。您的链接就像魅力一样工作:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-14
    • 2011-03-16
    • 2011-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多