- var data = data, fontsObj = fonts;
- spread.fromJSON(data);
- //注册字体
- registerServerFont('宋体', 'normal', '/Content/plugins/SpreadJs/font/simsun.ttf', true);
- function registerServerFont(name, type, serverPath, isSetFallback) {
- 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;
- if (name instanceof Array) {
- for (var i = 0; i < name.length; i++) {
- var fonts = GC.Spread.Sheets.PDF.PDFFontsManager.getFont(name[i]) || {};
- fonts[type] = fontrrayBuffer;
- GC.Spread.Sheets.PDF.PDFFontsManager.registerFont(name[i], fonts);
- }
- }
- else {
- var fonts = GC.Spread.Sheets.PDF.PDFFontsManager.getFont(name) || {};
- fonts[type] = fontrrayBuffer;
- GC.Spread.Sheets.PDF.PDFFontsManager.registerFont(name, fonts);
- }
- if (isSetFallback) {
- GC.Spread.Sheets.PDF.PDFFontsManager.fallbackFont = function (font) {
- if (font.indexOf("宋体") < 0) {
-
- return fonts.normal;
- }
- }
- }
- }
- reader.readAsArrayBuffer(blob);
- }
- };
- xhr.send();
- }
- spread.savePDF(function (blob) {
- saveAs(blob, title + '.pdf');
- }, function (error) {
- console.log(error);
- }, {
- title: title,
- author: '',
- subject: '',
- keywords: '',
- creator: ''
- });
复制代码
这段代码会出现导出还是乱码,按F12调试导出不会乱码 |