Ios 将UIView/图形上下文拆分为多个区域

Ios 将UIView/图形上下文拆分为多个区域,ios,objective-c,pdf,printing,graphicscontext,Ios,Objective C,Pdf,Printing,Graphicscontext,我正在尝试将UIView打印为PDF格式 问题是,如果UIView比页面高,它就会被切断 所以我想做的是迭代UIView的“页面高度”,并将它们呈现为PDF页面 这是我的密码: UIGraphicsBeginPDFContextToData(pdfData, CGRectMake(0, 0, 400, 782), nil); CGContextRef pdfContext = UIGraphicsGetCurrentContext(); UIGraphicsBeginPDFPage(); /

我正在尝试将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();
显然,目前它只是在每页上呈现相同的内容

CGContextBeginPDFPage();
CGContextTranslateCTM(pdfContext, 0.0, -782.0);
[self.receiptContentView.layer renderInContext:pdfContext];
我如何将上面的代码改为“只在第1页打印第一个782px,然后在第2页打印下一个782px”


非常感谢。

在开始每页时,尝试向上转换上下文

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