【问题标题】:iphone create pdf from set of imagesiphone从一组图像创建pdf
【发布时间】:2011-10-17 23:23:45
【问题描述】:

我在项目的文档目录中设置了几张图片。我想要在我的 iPhone 应用程序中从这些图像的文档目录本身中创建一个 pdf 文件。我的意思是带有多个图像的pdf。 我能够找到为单个图像创建 pdf,但找不到任何参考代码来创建多个图像的 pdf 文件。

谢谢。

【问题讨论】:

    标签: iphone image pdf


    【解决方案1】:

    在屏幕外UIWebView 中加载每个图像。然后对每个图像执行以下操作-

                CGRect r = CGRectMake(0, 0, 612, 792); //default PDF size
                CGContextBeginPage (pdfContext,nil); //pdfContext is the CGContextRef of the PDF document
                //turn PDF upsidedown   
                CGAffineTransform transform = CGAffineTransformIdentity;    
                transform = CGAffineTransformMakeTranslation(0, r.size.height);   
                transform = CGAffineTransformScale(transform, 1.0, -1.0);   
                CGContextConcatCTM(pdfContext, transform);  
                [self.webView.layer renderInContext:pdfContext];    
                CGContextEndPage (pdfContext);
    

    这样,每张图片都会出现在 PDF 的一页上。

    【讨论】:

    • 我已经通过创建页面解决了这个问题,然后在当前上下文中写入内容,然后结束页面。重复此过程创建多页 pdf 文档。
    猜你喜欢
    • 2011-10-27
    • 1970-01-01
    • 2015-02-04
    • 1970-01-01
    • 2012-02-17
    • 1970-01-01
    • 2011-08-30
    • 2013-07-25
    相关资源
    最近更新 更多