ios - 核心图转换为pdf时呈现为黑框

标签 ios objective-c pdf core-plot

我的应用程序使用Core Plot来渲染图形,最后需要创建一个pdf文件,应该有这个图形,但是当它保存到pdf文件时,我看到的不是图形,而是黑框。 我用来创建pdf的方法:

UIGraphicsBeginPDFContextToFile(outputPath, CGRectZero, nil);

for(UIView *view in views) {
    UIGraphicsBeginPDFPageWithInfo(view.bounds, nil);
    CGContextRef pdfContext = UIGraphicsGetCurrentContext();UIGraphicsBeginPDFContextToFile
    [view.layer renderInContext:pdfContext];
}

UIGraphicsEndPDFContext();

有人可以帮助如何使其正确渲染吗?

作为创建 pdf 之前的临时解决方案,我将图形转换为图像并将其放在其顶部,结果 pdf 正确呈现,是否有更优雅的解决方案?

编辑: 我应用了上述建议,代码如下所示:

        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];
    }

用户界面结果: enter image description here

结果是 pdf:

enter image description here

最佳答案

您是否使用了部分透明颜色的填充? Alpha channel 不会渲染为 PDF。这是 Apple PDF 框架长期存在的问题。

关于ios - 核心图转换为pdf时呈现为黑框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57353990/

相关文章:

ios - 这些是什么以及如何修复 Console.app 中的 "Could not find layout engine view for view' s ...”警告?

php - dompdf->渲染();不在 api 类中工作

pdf - 将PDF转换为图像后如何获得可读文本(带抗锯齿的文本)?

ios - 如何手动将 Swift 静态库集成到 Objective-C 或 Swift 项目中而不将其添加为子项目

ios - XCode 8 不正确的背景颜色 - Storyboard 更新的颜色空间

c# - 如何使用 C# 从 PDF 或 XPS 中提取具有格式的文本?

objective-c - 标签栏作为 View Controller 顶层 View 的 subview ;画得不正确

ios - 使用自适应布局的 iPhone 和 iPad 设备的不同 uitableview 单元格高度

ios - 未观察到 KVC NSKeyValueChangeRemoval

iphone - UITextfield 清除按钮