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 PDFhttps://github.com/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

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

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值