如何使用 jsPDF 从 SVG 轻松创建 PDF? [英] How do I create easily a PDF from an SVG with jsPDF?
问题描述
我正在尝试创建 pdf,但我有一些 SVG 图片.我找到了关于这个问题的信息,但我只需要使用 JavaScript,也就是说,没有 jQuery.
我在这里找到了 jsPDF:https://github.com/MrRio/jsPDF
有插件 jspdf.plugin.sillysvgrenderer.js(在同一文件夹中),我们可以在其中找到在文件夹 test 中创建的 PDF 示例.
但是当我尝试自己生成 PDF 时,它不起作用,我不明白为什么.
你知道怎么做吗?
尝试 canvg 将 SVG 转换为 Canvas.然后使用 .toDataURL()
将画布转换为 base64 字符串.
更详细的答案在这里https://stackoverflow.com/a/35788928/2090459
在此处查看演示 http://jsfiddle.net/Purushoth/hvs91vpq/>
Canvg 存储库:https://github.com/gabelerner/canvg
I'm trying to create a pdf but I have some SVG pictures. I found information about this problem, but I just have to use JavaScript, that's to say, no jQuery.
I found jsPDF here : https://github.com/MrRio/jsPDF
There is the plugin jspdf.plugin.sillysvgrenderer.js (in the same folder) and where we can find an exemple of PDF created in the folder test.
But when I try to generate the PDF on my own, it doesn't work and I don't understand why.
Do you know how to do it?
Try canvg for that to covert SVG to Canvas. Then convert the canvas to base64 string using .toDataURL()
.
More detailed answer is here https://stackoverflow.com/a/35788928/2090459
Check the demo here http://jsfiddle.net/Purushoth/hvs91vpq/
Canvg Repo: https://github.com/gabelerner/canvg
这篇关于如何使用 jsPDF 从 SVG 轻松创建 PDF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!