如何使用jsPDF从SVG轻松创建PDF? [英] How do I create easily a PDF from an SVG with jsPDF?

查看:81
本文介绍了如何使用jsPDF从SVG轻松创建PDF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建pdf,但是我有一些SVG图片.我找到了有关此问题的信息,但是我只需要使用JavaScript,也就是说,没有jQuery.

我在这里找到jsPDF: https://github.com/MrRio/jsPDF

在同一个文件夹中有一个插件 jspdf.plugin.sillysvgrenderer.js ,在这里我们可以找到在 test 文件夹中创建的一个PDF示例. /p>

但是当我尝试自行生成PDF时,它不起作用,我也不明白为什么.

你知道怎么做吗?

解决方案

尝试使用 canvg 可以将SVG转换为Canvas.然后使用.toDataURL()将canvas转换为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屋!

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