我正在尝试将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/