如何将UIView导出为PDF文件 [英] How to export UIView to PDF file
问题描述
在我的应用程序中实现导出PDF功能,用于导出的内容是 UIView
。现在我有一个列表数据,并使用for循环加载所有对象,每个对象将被加载到 UIView
并导出一个页面。输出文件应该有多页,但只有一个第一页。
I implement exporting PDF feature in my application, content used to export is UIView
. Now I have a list data and use for loop to load all objects, every object will be loaded in UIView
and export a page. The output file should have multipage but it has only one first page.
这是我的代码:
UIGraphicsBeginPDFContextToFile(path, CGRectZero, nil);
_context = UIGraphicsGetCurrentContext();
for (Entry *entry in listEntries) {
[self loadEntry:entry.date];
UIGraphicsBeginPDFPageWithInfo(CGRectMake(0.0f, -160.0f, 768.0f, 660.0f), nil);
[self.layer renderInContext:_context];
UIGraphicsEndPDFContext();
}
提前感谢
推荐答案
有没有一个 UIGraphicsEndPDFPageWithInfo()
或类似的东西?您需要决定何时将内容溢出,并在将其转换为PDF之前启动新页面。至少这是我以前用CoreGraphics做这样的事情时所做的。如果没有 EndPage
函数,或许只需另外调用 BeginPage
就可以了。
Is there a UIGraphicsEndPDFPageWithInfo()
or something like that? You need to decide when your content will spill over, and start a new page before rendering it to the PDF. At least that's what I used to do when I used CoreGraphics to do this kind of thing. If there is no EndPage
function, perhaps just another call to BeginPage
will do the trick.
这篇关于如何将UIView导出为PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!