使用JS将SVG导出为PDF

使用JS将SVG导出为PDF

本文介绍了在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 以及。它工作正常。不幸的是,这不支持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图像的可能性,以及 似乎是目前从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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 13:26