ios - 将UIView/图形上下文划分为多个区域

标签 ios objective-c pdf printing graphicscontext

我正在尝试将UIView打印为PDF。

问题是,如果UIView高于页面,则会被截断。

因此,我想做的是遍历UIView的“页面高度”,并将它们分别呈现为PDF页面。

这是我的代码:

UIGraphicsBeginPDFContextToData(pdfData, CGRectMake(0, 0, 400, 782), nil);
CGContextRef pdfContext = UIGraphicsGetCurrentContext();

UIGraphicsBeginPDFPage();

// draws rect to the view and thus this is captured by UIGraphicsBeginPDFContextToData
[self.receiptContentView.layer renderInContext:pdfContext];

UIGraphicsBeginPDFPage();

// draws rect to the view and thus this is captured by UIGraphicsBeginPDFContextToData
[self.receiptContentView.layer renderInContext:pdfContext];

// remove PDF rendering context
UIGraphicsEndPDFContext();

显然,目前它只是在每个页面上呈现相同的内容。

我如何将上面的代码更改为“仅在第1页上打印第一个782px,然后在第2页上打印下一个782px”?

非常感谢。

最佳答案

启动每个页面时,尝试向上转换上下文。

CGContextBeginPDFPage();
CGContextTranslateCTM(pdfContext, 0.0, -782.0);
[self.receiptContentView.layer renderInContext:pdfContext];

关于ios - 将UIView/图形上下文划分为多个区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15392066/

相关文章:

ios - UITabBarController 不显示其他选项卡的标题

pdf - 如何从 DeepSee Dashboards 进行打印?

c# - 显示来自 Reporting Services 的 PDF

ios - 切换到 XCode 7.0(.1) 后,自定义 View (XIB) 在 Release模式下崩溃

IOS:在 iOS 应用程序中转换广告

ios - 在 React Native 中禁用 IOS 键盘建议

Adobe Acrobat 的 JavaScript API - 如何使用 JavaScript 创建指向非 PDF 文档的相对链接?

ios - 如何以编程方式在 iOS 上的当前 Crashlytics (3.14.*)/Firebase (1.10.*) 中禁用 CrashReporting

ios - ReactiveCocoa 中的 Map 或 flattenMap

php - 加密发送到 PHP Web 服务的数据