var fontsObj = fonts;
// setting printInfo
setPrintInfo(spread);
// add custom font to fontManager
addFontsToFontManager(fontsObj);
registerServerFont('宋体', 'normal', 'font/simsun.ttf');
registerServerFont('simsun', 'normal', 'font/simsun.ttf');
}
function registerServerFont(name, type, serverPath) {
var xhr = new XMLHttpRequest();
xhr.open('GET', serverPath, true);
xhr.responseType = 'blob';
xhr.onload = function (e) {
if (this.status == 200) {
// get binary data as a response
var blob = this.response;
//将Blob 对象转换成 ArrayBuffer
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();
}
function addFontsToFontManager(fontsObj) {
var fonts = {
normal: fontsObj["simkai.ttf"],
cache: {} // 添加一个标记缓存
};
GC.Spread.Sheets.PDF.PDFFontsManager.fallbackFont = function (font) {
var fontInfoArray = font.split(' '), fontName = fontInfoArray[fontInfoArray.length - 1];
console.log(fontName);
if (fontName !== 'Yahei' && !fonts.cache[fontName]) {
fonts.cache[fontName] = true;
return fonts.normal;
}
}
}
但是你一开始还是加载了fonts.js文件 这样的话 一开始很卡 我的是angular的项目 就是你打开这个网站的时候要等几十秒不等 看网速 |