首页 文章

将SVG转换为PNG和PDF命令行

提问于
浏览
0

我有一个SVG文件,我想将其转换为在PDF中使用它 .

它在我的浏览器(chrome,edge,firefox)上呈现得很好 . 文件在这里:https://gist.github.com/acourdavault/329b8670517e0716cd38eab202e2ca0e

它包括渐变
enter image description here

我尝试了magick,inkskape,librsvg2将其转换为png和/或pdf . the biggest problem is that stop-color and stop-color-opacity are not supported
enter image description here
注意,这里只有inkscape给出这个消息,其他转换器不提供任何信息,即使是冗长但结果很可怕```bash

(inkscape:648850):警告:未实现的样式属性SP_PROP_STOP_COLOR:value:#ffa500

(inkscape:648850):警告:未实现的样式属性SP_PROP_STOP_OPACITY:值:0.59999999999999998

(inkscape:648850):警告:未实现的样式属性SP_PROP_STOP_COLOR:value:#ffff00``

PDF(保持格式矢量)我想是理想的,但 i need to be able to run this from the command line.

Do you have an idea of why, this does not work and how to fix it?

备注我使用SVG类,但样式在SVG本身的样式§中


解决方案

Solution from ccprog

我在svg xml的顶部移动了defs,我使用了fill = url(#gradientid)来声明渐变而不是类我替换了stop-color和stop-opacity的定义,即在类中将它们内联在哪里停止标签 .

1 回答

  • 1

    这里的问题是浏览器旁边的各种渲染器不能很好地支持样式表 . 您需要内联所有样式才能使其正常工作

    Personal advertisement: 我为该任务编写了一个节点模块:svg-icon-toolbox . 您可以加载文件,执行 inline 任务并使用 write 将其写回 . 然后可以在回调的衍生过程中完成PDF转换 .

    第二个问题是在使用后说明渐变 . 根据规范它完全有效,但librsvg不喜欢它 . Inkscape会很好 . (在系统上存在Inkscape或librsvg时,magick将使用其中一个进行渲染,因此这是多余的 . )

相关问题