找回密码
 立即注册

QQ登录

只需一步,快速开始

theCL

注册会员

3

主题

7

帖子

22

积分

注册会员

积分
22
  • 577

    金币

  • 3

    主题

  • 7

    帖子

最新发帖
theCL
注册会员   /  发表于:2024-4-22 09:16  /   查看:263  /  回复:1
// 注册字体,上传 中文字体 到服务中,解决中文乱码问题
function registerServerFont(name: any, type: any, serverPath: any) {
  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: any = {};
        fonts[type] = fontrrayBuffer;
        GC.Spread.Sheets.PDF.PDFFontsManager.registerFont(name, fonts);
      };
      reader.readAsArrayBuffer(blob);
    }
  };

  xhr.send();
}// publicPath 为项目 public 静态资源地址 (本地为'', 但在服务器中为 base 地址)registerServerFont('微软雅黑', 'normal', `${publicPath}/微软雅黑.ttf`);

!!!!!注册字体的操作同一份文档只用注册一次就行,如果在新增的时候注册了,又在编辑的时候再次注册,会导致 pdf 导出功能无响应


评分

参与人数 1金币 +500 收起 理由
Joestar.Xu + 500 赞一个!

查看全部评分

1 个回复

倒序浏览
Joestar.XuSpreadJS 开发认证
超级版主   /  发表于:2024-4-22 10:30:51
沙发
感谢分享解决方案,已为您送上500金币~
SpreadJS 17.0.8 | GcExcel 7.1.1 已发布~
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部