1金币
看了论坛中很多文章,使用了方法但是还是乱码
代码如下
//注册PDF导出字体
const registerServerFont = (name, type, serverPath) => {
var xhr = new XMLHttpRequest();
xhr.open('GET', serverPath, true);
xhr.responseType = 'blob';
xhr.onload = function (e) {
console.log(e)
if (e.target.status == 200) {
var blob = e.target.response;
var reader = new FileReader();
reader.onload = function (e) {
var fontrrayBuffer = reader.result;
var fonts = GC.Spread.Sheets.PDF.PDFFontsManager.getFont(name) || {};
fonts[type] = fontrrayBuffer;
GC.Spread.Sheets.PDF.PDFFontsManager.registerFont(name, fonts);
};
reader.readAsArrayBuffer(blob);
}
};
xhr.send();
}
registerServerFont('微软雅黑', 'normal', 'src/utils/font/msyh.ttf');
registerServerFont('Microsoft Yahei', 'normal', 'src/utils/font/msyh.ttf');
registerServerFont('simsun', 'normal', 'src/utils/font/simsun.ttf');
registerServerFont('simsun', 'bold', 'src/utils/font/simsunbd.ttf');
const handlePDF = () => {
// 导出pdf
spread.savePDF((blob) => {
saveAs(blob, '测试' + '.pdf');
},
function (error) {
console.log(error);
},
);
};
导出打开如下
|
最佳答案
查看完整内容
你这边的代码还是有问题,可以向详细看一下我们的学习指南和API
https://demo.grapecity.com.cn/spreadjs/SpreadJSTutorial/features/pdf/custom-font-export-pdf/purejs
https://demo.grapecity.com.cn/spreadjs/help/api-15.1/GC.Spread.Sheets.PDF.PDFFontsManager.html#.registerFont
以GC.Spread.Sheets.PDF.PDFFontsManager.registerFont('SimSun', font);为例,
font 参数给的是CSS字体字符串base64字符串或ArrayBu ...
|