Reputation: 466
I my application used Core Plot to render graphs, and finally there is a need to create a pdf file, there should be this graph, but when it is saved to pdf file, instead of graph I see black box. The method I use to create a pdf:
UIGraphicsBeginPDFContextToFile(outputPath, CGRectZero, nil);
for(UIView *view in views) {
UIGraphicsBeginPDFPageWithInfo(view.bounds, nil);
CGContextRef pdfContext = UIGraphicsGetCurrentContext();UIGraphicsBeginPDFContextToFile
[view.layer renderInContext:pdfContext];
}
UIGraphicsEndPDFContext();
Could someone help how to make it render properly?
As a temporary solution before creating a pdf I convert graph to image and put it on the top of it as a result pdf is rendered properly, Is there any more elegant solution?
Edited: I applied the above advice the code looks like this:
if([child isKindOfClass:[CPTGraphHostingView class]]) {
CGContextTranslateCTM(pdfContext, child.center.x, child.center.y);
CGAffineTransform transform = CGAffineTransformMakeRotation(0);
transform.d = -1;
CGContextConcatCTM(pdfContext, transform);
CGContextTranslateCTM(pdfContext,
child.bounds.size.width * 0.05,
-child.bounds.size.height * 0.75);
CPTLayer *layer = (CPTLayer *)((CPTGraphHostingView *)child).hostedGraph;
[layer layoutAndRenderInContext:pdfContext];
}
and as a result is pdf:
Upvotes: 0
Views: 106
Reputation: 27381
Are you using any fills with partially transparent colors? The alpha channel doesn't render into PDF. This is a long-standing issue with the Apple PDF frameworks.
Upvotes: 1