Maintain vector graphics when rendering CALayer into PDF output

99封情书 提交于 2020-02-01 07:22:04

问题


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.).

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.

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.


回答1:


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.



来源:https://stackoverflow.com/questions/13783971/maintain-vector-graphics-when-rendering-calayer-into-pdf-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!