【问题标题】:Generate a pdf from opengles context in iphone/ipad从 iphone/ipad 中的 opengles 上下文生成 pdf
【发布时间】:2012-03-25 22:33:25
【问题描述】:
您好,我是 PDF 生成的菜鸟,目前在我的 glview 应用程序中显示 3d 条形图,它位于 uiview 一侧。现在我想从包含文本视图和 glview 的 uiview 生成 PDF 文档。我能够从文本生成 PDF,但是 GL View 无法继续。即使我尝试通过网络寻找可能性,但无法获得有关此的任何信息。有人可以通过提供解决方案来帮助我,这是否可行或不是。提前致谢
【问题讨论】:
标签:
iphone
ios
ipad
opengl-es
pdf-generation
【解决方案1】:
您可以通过以下方式要求任何 UIView 给您一张图片(这可能是一个开始):
- (UIImage *) imageRepresentation {
// render myself (or more correctly, my layer) to an image
UIGraphicsBeginImageContext(self.bounds.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetShouldSmoothFonts(context, false);
CGContextSetShouldAntialias(context, false);
[self drawLayer:self.layer inContext:context];
[self.layer renderInContext:context];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
之后,您可能能够获得它的 PDF 表示,或者调查像 CGPDFDocumentCreateWithURL 这样的调用,以自己从图像构建一个。