我一直试图获得UIScrollView的全长打印输出。我可以加载UIScrollView,并可以使用下面的代码在Printout的第一页中获取部分视图:
CGSize viewSize=((UIScrollView*)myScrollview).contentSize;
CGFloat currentHeight=0;
UIGraphicsBeginPDFContextToData(pdfData, CGRectZero, nil);
[(UIScrollView*)myScrollview setContentOffset:CGPointMake(0, 0) animated:NO];
while (currentHeight<viewSize.height)
{
UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, viewSize.width, 792), nil);
CGContextRef pdfContext = UIGraphicsGetCurrentContext();
myScrollview.bounds=CGRectMake(0,0,viewSize.width,viewSize.height);
myScrollview.layer.bounds = CGRectMake(0, currentHeight,viewSize.width,viewSize.height);
[myScrollview.layer renderInContext:pdfContext];
currentHeight+=612;
[(UIScrollView*)myScrollview setContentOffset:CGPointMake(0, currentHeight) animated:NO];
}
[(UIScrollView*)myScrollview setContentOffset:CGPointMake(0, 0) animated:NO];
UIGraphicsEndPDFContext();
此代码在第一页中显示ScrollView的部分内容。我希望它分成多个页面进行打印。
欢迎所有帮助。