Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/100.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 将shinobi图表打印为PDF_Ios_Objective C_Pdf_Uigraphicscontext_Shinobi - Fatal编程技术网

Ios 将shinobi图表打印为PDF

Ios 将shinobi图表打印为PDF,ios,objective-c,pdf,uigraphicscontext,shinobi,Ios,Objective C,Pdf,Uigraphicscontext,Shinobi,我的应用程序中有几个shinobicharts,我想打印成PDF文件。其他一切,如普通视图、标签和图像,都可以正常工作,甚至显示栅格、图例和栅格标签。唯一缺少的就是这个系列。所以基本上我得到一个空的图表打印到PDF文件中 我将PDF打印如下: NSMutableData * pdfData=[NSMutableData data]; PDFPage1ViewController *pdf1 = [self.storyboard instantiateViewControllerWithIdent

我的应用程序中有几个shinobicharts,我想打印成PDF文件。其他一切,如普通视图、标签和图像,都可以正常工作,甚至显示栅格、图例和栅格标签。唯一缺少的就是这个系列。所以基本上我得到一个空的图表打印到PDF文件中

我将PDF打印如下:

NSMutableData * pdfData=[NSMutableData data];
PDFPage1ViewController *pdf1 = [self.storyboard instantiateViewControllerWithIdentifier:@"PDF1"];
pdf1.array1 = array1;
pdf1.array2 = array2;
pdf1.array3 = array3;
pdf1.array4 = array4;
UIGraphicsBeginPDFContextToData(pdfData, CGRectZero,nil);
CGContextRef pdfContext=UIGraphicsGetCurrentContext();
UIGraphicsBeginPDFPage();
[pdf1.view.layer renderInContext:pdfContext];
UIGraphicsEndPDFContext();
PDF1PageViewController中完全相同的代码在普通的viewController中绘制漂亮的图表,而不缺少该系列。 数组包含应显示的数据

[编辑]

这段代码为我做到了:

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

尽管活动控制盘在
drawViewHierarchyInRect
之后停止旋转,并且显示当前呈现页面的标签也停止更新。有人知道如何解决此问题吗?

出现此问题的原因是图表的系列部分在openGLES中呈现,因此不会作为
renderInContext:
的一部分呈现

您可以使用几个选项进行调查。第一个是在iOS7中的
UIView
上添加了一些快照方法。如果您的应用程序只能限于iOS7,则
SnapshotViewAfterScreenuUpdate:
将返回内容的快照
UIView
。我认为以下(未经测试的)代码可以工作:

UIGraphicsBeginPDFPage();
UIView *pdfPage = [pd1.view snapshotViewAfterScreenUpdates:YES];
[pdfPage.layer renderInContext:pdfContext];
UIGraphicsEndPDFContext();
在ShinobiControls的博客上有更多关于这种方法的详细信息

如果将应用程序限制在iOS7上不是一个选项,那么你仍然可以实现你想要的结果,但这有点复杂。幸运的是,ShinobiControls博客()上有一篇博客文章,描述了如何从图表创建
UIImage
。这可以很容易地调整为渲染到PDF上下文中,而不是在文章中创建的图像上下文中。这篇文章还有一个附加的代码片段,可在github上找到:

希望这有帮助


山姆

非常感谢!先生,你是我的救世主;)你的代码对我不起作用,但它给了我提示。请看我编辑的问题,找到正确的代码。谢谢!你的回答也帮了我