Printing shinobi chart into PDF on iOS7


I have several shinobicharts in my App that I want to print into a PDF file. Everything else, like normal views, labels and images work fine, even the grid, legend and gridlabels are displayed. The only thing missing are the series. So basically I get an empty chart printed into the PDF file.

I print the PDF as follows:

NSMutableData* pdfData=[NSMutableData data];PDFPage1ViewController*pdf1 =[self.storyboard instantiateViewControllerWithIdentifier:@"PDF1"];
pdf1.array1 = array1;
pdf1.array2 = array2;
pdf1.array3 = array3;
pdf1.array4 = array4;
CGContextRef pdfContext=UIGraphicsGetCurrentContext();
UIGraphicsBeginPDFPage();[pdf1.view.layer renderInContext:pdfContext];

The exact same code from PDF1PageViewController draws beautiful charts in a normal viewController, not missing the series. The arrays contain the data which should be displayed.


This code did it for me:

UIGraphicsBeginImageContextWithOptions(pdf1.view.bounds.size, NO, 0.0);
[pdf1.view drawViewHierarchyInRect:pdf1.view.bounds afterScreenUpdates:YES];
UIImage *pdf1Image = UIGraphicsGetImageFromCurrentImageContext();
UIImageView *pdf1ImageView = [[UIImageView alloc] initWithImage:pdf1Image];
[pdf1ImageView.layer renderInContext:pdfContext];

Although the activity wheel stops spinning after drawViewHierarchyInRect and the label displaying the current page being rendered also stops updating. Anyone knows how to fix this?

Link to the related StackOverflow post