前端html转pdf

2019-04-04  本文已影响0人  xiaoyao911209

注:1、目前前端大段html转pdf的方法大多数都会使用canvas 截图的方法,所以生成的pdf打印出来都会稍微有颗粒感,如果对清晰度有严格的要求,可能需要另觅它法。

2、大段文本转pdf也有不使用canvas截图的方法,就是用jspdf一句一句的拼成pdf,缺点:1)jspdf不支持中文,需要字体转码后引入,2)耗时。

一:使用html2canvasjsPDF

https://github.com/niklasvh/html2canvas

https://github.com/MrRio/jsPDF

<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.debug.js"></script>

代码:

css html script

二:jspdf拼成pdf

请参考

http://www.hangge.com/blog/cache/detail_2207.html

https://blog.csdn.net/kunga0814/article/details/81869183

上一篇下一篇

猜你喜欢

热点阅读