Shift the origin between renders with CGContextTranslateCTM
:
+ (NSData*)pdfFromViews:(NSArray*)views {
NSMutableData* pdf = [NSMutableData data];
UIGraphicsBeginPDFContextToData(pdf, CGRectZero, nil);
UIGraphicsBeginPDFPage();
CGContextRef context = UIGraphicsGetCurrentContext();
for(UIView *view in views) {
[view.layer renderInContext:context];
CGContextTranslateCTM(context, 0, view.bounds.size.height);
}
UIGraphicsEndPDFContext();
return pdf;
}
You may also want to specify a page size that fits your views. Calculate the size and call UIGraphicsBeginPDFPageWithInfo
instead of UIGraphicsBeginPDFPage
.