失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > bootstrap table export插件导出pdf格式文件中文乱码问题解决办法

bootstrap table export插件导出pdf格式文件中文乱码问题解决办法

时间:2020-07-25 14:19:34

相关推荐

bootstrap table export插件导出pdf格式文件中文乱码问题解决办法

bootstrap table export插件导出pdf格式文件中文乱码的问题折腾了我整整两天,网上到处都是改源码,自己设置字体的方案,我都没搞定。结果今天看到官方文档(地址:GitHub - hhurz/tableExport.jquery.plugin: jQuery plugin to export a html table to JSON, XML, CSV, TSV, TXT, SQL, Word, Excel, PNG and PDFjQuery plugin to export a html table to JSON, XML, CSV, TSV, TXT, SQL, Word, Excel, PNG and PDF - GitHub - hhurz/tableExport.jquery.plugin: jQuery plugin to export a html table to JSON, XML, CSV, TSV, TXT, SQL, Word, Excel, PNG and PDF/hhurz/tableExport.jquery.plugin)里直接给出了解决办法:

Many HTML stylings can be converted to PDF with jsPDF, but support for non-western character sets is almost non-existent. Especially if you want to export Arabic or Chinese characters to your PDF file, you can use pdfmake as an alternative PDF producer. The disadvantage compared to jspdf is that using pdfmake has a reduced styling capability. To use pdfmake enable the pdfmake option and instead of the jsPDF files include

<script type="text/javascript" src="libs/pdfmake/pdfmake.min.js"></script><script type="text/javascript" src="libs/pdfmake/vfs_fonts.js"></script><!-- To export arabic characters include mirza_fonts.js _instead_ of vfs_fonts.js<script type="text/javascript" src="libs/pdfmake/mirza_fonts.js"></script>--><!-- For a chinese font include either gbsn00lp_fonts.js or ZCOOLXiaoWei_fonts.js _instead_ of vfs_fonts.js <script type="text/javascript" src="libs/pdfmake/gbsn00lp_fonts.js"></script>-->

。这段话的意思是说,如果需要支持非西方字母集,可以不用jsPDF而用pdfmaker来生成pdf,如果需要支持中文字符,那么额外引用字体文件gbsn00lp_fonts.js。

因此,在html的head中,引入如下js文件

<script type="text/javascript" src="tableExport.min.js"><script type="text/javascript" src="libs/FileSaver/FileSaver.min.js"><script type="text/javascript" src="libs/pdfmake/pdfmake.min.js"></script><script type="text/javascript" src="libs/pdfmake/gbsn00lp_fonts.js"></script><script type="text/javascript" src="bootstrap-table-export.min.js"></script>

再在导出表格的选项中设置使用pdfmake来导出pdf文件

var options={.....showExport:true,exportTypes:['pdf','txt'],exportOptions:{fileName:'123',pdfmake:{enabled:true}}....}$('#表格ID').bootstrapTable('destory').bootstrapTable(options);

这样导出的pdf文件就不会中文乱码啦。

ps:所有的文件都是在

GitHub - hhurz/tableExport.jquery.plugin: jQuery plugin to export a html table to JSON, XML, CSV, TSV, TXT, SQL, Word, Excel, PNG and PDF

这里下载的。顺便说,项目代码无法复制,可能会有抄过来的笔误,但是方案是可行的。

如果觉得《bootstrap table export插件导出pdf格式文件中文乱码问题解决办法》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。