【问题标题】:Angular 6: How I use jspdf-customfontsAngular 6:我如何使用 jspdf-customfonts
【发布时间】:2018-09-07 15:37:30
【问题描述】:

起初我陷入了 jspdf。它的工作非常好。现在我想使用 UTF-8 字体 我创建了一个自定义字体,例如 this example

为此,我安装: npm i jspdf-customfonts 我创建 default_vjs.js 文件:

(function (jsPDFAPI) { 
"use strict";
jsPDFAPI.addFileToVFS('PTSans-Regular.ttf', 'Base64-encoded string of my font');
jsPDFAPI.addFileToVFS('PTSans-Bold.ttf', 'Base64-encoded string of my font'); })(jsPDF.API);

并将其保存在路径中:scr/app/js/default_vfs.js

我在我的组件中测试它:

import * as jsPDF from 'jspdf';

.......

const test = new jsPDF('p', 'mm', 'a4');
 test.addFont('PTSans-Regular.ttf', 'PTSans', 'normal');
 test.addFont('PTSans-Bold.ttf', 'PTSans', 'bold');
 test.setFont('PTSans');
 test.setFontType('normal');
 test.text(10, 10, 'Hallo Welt € ');
 test.save('customFont.pdf');

但它不起作用。模具€符号是错误的。有人可以告诉我我做错了什么吗?

【问题讨论】:

    标签: angular6 jspdf custom-font


    【解决方案1】:

    我解决了我的问题:
    regularNormal 是我的字体的 Base64 编码字符串。

    AddFontArimo(doc: jsPDF) {
       (doc as any).addFileToVFS('arimo.regular-normal.ttf', this.regularNormal);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多