我使用Datatable js来管理我的表,但在尝试导出pdf文件时遇到编码Arabic Words
的问题,所以我正在尝试更改pdfMake
中的默认字体
所以我做了
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/vfs_fonts.js"></script>
<script>
pdfMake.fonts = {
Arial: {
normal: 'Arial.ttf',
bold: 'Arial.ttf',
italics: 'Arial.ttf',
bolditalics: 'Arial.ttf'
}
};
var buttons = new $.fn.dataTable.Buttons(datatable, {
buttons: [{
extend: 'copyHtml5',
title: documentTitle
},
{
extend: 'excelHtml5',
title: documentTitle
},
{
extend: 'csvHtml5',
title: documentTitle
},
{
extend: 'pdfHtml5',
title: documentTitle,
customize: function(doc) {
doc.defaultStyle.font = 'Arial';
},
}
]
}).container().appendTo($('#report_views_export'));
</script>
但我在控制台Uncaught (in promise) File 'Arial.ttf' not found in virtual file system
中收到了这个消息
您需要在文件vfs_fonts.js
中添加字体。要做到这一点,您必须将每个字体文件编码为64进制格式,并将64进制字符串放入文件vfs_fonts.js
中。
文件vfs_fonts.js
将类似
this.pdfMake = this.pdfMake || {}; this.pdfMake.vfs = {
"arial.ttf": "AAEAAAAXAQAABABwRFNJRyQ9+ecAB..........",
"arialbd.ttf":"AAEAAAAXAQAABABwRFNJR8zIlFoA..........",
"ariali.ttf":"AAEAAAAXAQAABABwRFNJRy1JDhMAC..........",
"arialbi.ttf":"AAEAAAAYAQAABACARFNJRxk7cD4A.........."
};