Digunakan untuk menyelesaikan masalah kode kacau Cina saat membuat pdfmake, pdfhtml5, datatables
Saat ini widget terkecil untuk membuat file font setelah mendukung encoding base64 vfs_js Cina
Secara default, font Cina terkecil diintegrasikan dengan 2 gaya tebal dan gaya biasa, yang hanya 1,7m. Itu harus menjadi font Cina terkecil saat ini! Lai
Pertama -tama, Anda perlu menginstal lingkungan simpul. Saat ini, semua versi node v16, 14, 12, dan 10 baik -baik saja.
Kedua, masukkan file font VFS yang ingin Anda hasilkan ke folder font, dan kemudian jalankan instalasi CNPM && npm run build
cnpm install
# 构建 vfs_fonts.js
npm run buildPerhatikan bahwa semua font di bawah folder Fonts akan dikemas. Jika Anda tidak memerlukan roboto font default resmi, Anda dapat menghapus file robotoo-xxx!
Ubah skrip yang sesuai dengan skrip dalam file package.json
"scripts" : {
"build:vfs" : " node node_modules/pdfmake/build-vfs.js " ./fonts " " ./build/vfs_fonts.js " "
},Build-vfs.js nama file VFS yang dihasilkan oleh folder yang menyimpan font
Search for var defaultClientFonts = {} in the pdfmake.js file, register the vfs font you generated, register the font name and the corresponding font style corresponding to the font name {normal:xxx, bold:xxx, italic:xxx, bold italic:xxx}, and use the font name registered here directly when using it.
var defaultClientFonts = {
Hyzh : {
normal : 'hyzjh_zh.ttf' ,
bold : 'hylxt_bold.ttf' ,
italics : 'hyzjh_zh.ttf' ,
bolditalics : 'hylxt_bold.ttf'
} ,
Roboto : {
normal : 'Roboto-Regular.ttf' ,
bold : 'Roboto-Medium.ttf' ,
italics : 'Roboto-Italic.ttf' ,
bolditalics : 'Roboto-MediumItalic.ttf'
}
} ;Konfigurasi default
var defaultClientFonts = {
Roboto : {
normal : 'Roboto-Regular.ttf' ,
bold : 'Roboto-Medium.ttf' ,
italics : 'Roboto-Italic.ttf' ,
bolditalics : 'Roboto-MediumItalic.ttf'
}
} ; <!DOCTYPE html >
< html lang =" zh-CN " >
< head >
< meta charset =" utf-8 " >
< title > Pdfmake export Chinese PDF </ title >
< script src =" pdfmake.min.js " > </ script >
< script src =" vfs_fonts.js " > </ script >
< script >
function down ( data ) {
var doc = {
content : [
data ,
'Another paragraph, this time a little bit longer to make sure, this line will be divided into at least two lines'
] ,
defaultStyle : {
font : 'Hyzh' ,
fontSize : 12
}
} ;
pdfMake . fonts = {
Roboto : {
normal : 'Roboto-Regular.ttf' ,
bold : 'Roboto-Medium.ttf' ,
italics : 'Roboto-Italic.ttf' ,
bolditalics : 'Roboto-Italic.ttf'
} ,
Hyzh : {
normal : 'hyzjh_zh.ttf' ,
bold : 'hylxt_bold.ttf' ,
italics : 'hyzjh_zh.ttf' ,
bolditalics : 'hylxt_bold.ttf'
}
} ;
pdfMake . createPdf ( doc ) . download ( ) ;
}
</ script >
</ head >
< body >
< button onclick =" down('最小的支持中文显示的pdf生成工具') " >下载</ button >
</ body >
</ html > Informasi lebih lanjut https://datatables.net/reference/button/pdfhtml5 https://datatables.club/reference/button/pdfhtml5.html