admin管理员组文章数量:1594755
前言
jspdf插件用于生成pdf文件,功能非常强大,但是美中不足是没有中文字体,使用中文的话需要单独下载
引用官方文档的话:
The 14 standard fonts in PDF are limited to the ASCII-codepage. If you want to use UTF-8 you have to integrate a custom font, which provides the needed glyphs. jsPDF supports .ttf-files. So if you want to have for example Chinese text in your pdf, your font has to have the necessary Chinese glyphs. So, check if your font supports the wanted glyphs or else it will show garbled characters instead of the right text.
一.下载中文字体
1.寻找字体
网络很多推荐思源中文字体,但是那个字体文件太大了,几十M,放到项目可能打不开页面,这里推荐一个免费商用字体网站:字体天下,里面字体很多,而且可以寻找自己喜欢的字体
2.下载字体及js文件转换
下载完成解压后看到一个ttf文件
打开js转换工具
输入字体名称,选择文件点击生成即可,这里字体名称就是后边doc.setFont("jianbaosong");
括号中的名称
二.使用字体
把生成的js文件放入项目中,然后pdf对象引用即可
const doc = new jsPDF();
doc.setFont("jianbaosong");
三. 最后
jsPDF官方文档:https://artskydj.github.io/jsPDF/docs/jsPDF.html#line
版权声明:本文标题:下载免费的中文字体及生成jsPDF需要的js文件 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/xitong/1728200815a1149350.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论