【发布时间】:2011-10-17 23:23:45
【问题描述】:
我在项目的文档目录中设置了几张图片。我想要在我的 iPhone 应用程序中从这些图像的文档目录本身中创建一个 pdf 文件。我的意思是带有多个图像的pdf。 我能够找到为单个图像创建 pdf,但找不到任何参考代码来创建多个图像的 pdf 文件。
谢谢。
【问题讨论】:
我在项目的文档目录中设置了几张图片。我想要在我的 iPhone 应用程序中从这些图像的文档目录本身中创建一个 pdf 文件。我的意思是带有多个图像的pdf。 我能够找到为单个图像创建 pdf,但找不到任何参考代码来创建多个图像的 pdf 文件。
谢谢。
【问题讨论】:
在屏幕外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 的一页上。
【讨论】: