将CALayer转换为PDF输出时,请保持矢量图形 [英] Maintain vector graphics when rendering CALayer into PDF output

查看:122
本文介绍了将CALayer转换为PDF输出时,请保持矢量图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将许多数据点的绘图渲染到由NSView托管的CALayer中。 CALayer的drawInContext:中的所有绘制操作都是向量操作(CGPath等)。

I am rendering a plot with many data points into a CALayer that is hosted by an NSView. All drawing operations done within drawInContext: of the CALayer are vector operations (CGPaths etc.).

现在我想导出为PDF文件。使用CGPDFContextCreateWithURL(),创建一个PDF文件,但它本质上只包含我的情节的屏幕截图,意味着视图内容的位图图像。

Now I would like to export this as a PDF file. Using CGPDFContextCreateWithURL(), a PDF file is created, but it essentially just contains a screenshot of my plot, meaning a bitmap image of the the contents of the view.

但是我想要的是基于矢量的PDF。我知道CALayers将它们的内容在屏幕外呈现为一个位图,然后显示在屏幕上,但为什么不能渲染与矢量图形相同的内容?

But what I want is vector-based PDF. I know that CALayers render their content offscreen into a bitmap which is then shown on screen, but why is it not possible to render the very same content as a vector graphics instead?

是否真的没有内置的方法来实现呢?我不能是唯一需要这个的人。

Is there really no built-in way to achieve this? I must not be the only one needing this.

推荐答案

你需要重写你的代码,应该在PDF上下文上绘制,不要在PDF上下文中渲染CALayer,因为您将获得位图输出。

You need to rewrite your code, the code that draws on the CALayer context should draw also on the PDF context, do not render the CALayer on PDF context because you will get the bitmap output.

这篇关于将CALayer转换为PDF输出时,请保持矢量图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆