在PDF中嵌入SVG(使用JS将SVG导出为PDF) [英] Embedding SVG in PDF (exporting SVG to PDF using JS)

查看:357
本文介绍了在PDF中嵌入SVG(使用JS将SVG导出为PDF)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

起点:我没有可以提供静态文件的服务器。我在我的< body> 中有一个SVG元素(动态创建),我想导出为矢量格式,最好是PDF或SVG。

The starting points: I don't have a server that can provide anything but static files. And I have an SVG element (dynamically created) in my <body> that I want to export to a vector format, preferrably PDF or SVG.

我开始考虑使用现有的lib jsPDF 以及downloadify 。它工作正常。不幸的是,这不支持SVG,只支持文本。

I started looking at using the already existing lib jsPDF along with downloadify. It worked fine. Unfortunately, this does not support SVG, only text.

我已经阅读了PDF格式嵌入SVG图像的可能性,以及似乎已经启用了Acrobat Reader 5(以及ImageViewer插件)。但它不起作用。我试过使用3种不同的PDF阅读器但没有成功。

I've read about the PDF format's possiblities to embed SVG images, and it seems to have been enabled since Acrobat Reader 5 (along with the ImageViewer plugin). But it doesn't work. I've tried with 3 different PDF readers without success.

这是否意味着PDF已经放弃了SVG嵌入支持?我还没有找到任何相关内容。

Does this mean that PDFs has dropped SVG embedding support? I haven't found anything on this.

我有两个问题;这可以解决吗?如果是,那么在PDF中嵌入SVG的规范是什么?有了这些信息,我可以自己在jsPDF中构建支持。

I have two questions; can this be solved? And if yes, what are the specifications for embedding SVG inside of a PDF? With that info, I can build that support in jsPDF myself.

浏览器支持需求是Safari,Chrome和Firefox。支持SVG的版本。

The browser support demands are Safari, Chrome and Firefox. The versions that supports SVG.

推荐答案

对于任何寻找仅限JS的解决方案的人: PDFKit 似乎是目前从JS生成PDF的优秀解决方案,它支持所有SVG几何原语(包括解释路径几何字符串)开箱即用。渲染现有SVG内容所需的只是一个DOM-walker,它可以跟踪CSS样式和继承,如果你不需要像符号等复杂的东西。

For anyone looking for a JS-only solution: PDFKit seems to be the superior solution to generate PDF from JS these days, and it supports all SVG geometry primitives (including interpreting path geometry strings) out of the box. All that would be needed to render existing SVG content would be a DOM-walker that keeps track of CSS styling and inheritance, if you do not require complex stuff like symbols etc.

我对其他答案中提到的 jsPDF / svgToPdf 组合的粗略SVG支持没有成功,这两个的源代码看起来不太好-crafted and complete to me。

I wasn't successful with the sketchy SVG support of the jsPDF/svgToPdf combo mentioned in the other answer, and the source code of these two didn't look very well-crafted and complete to me.

这篇关于在PDF中嵌入SVG(使用JS将SVG导出为PDF)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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