我正在使用带有 fromHtml 插件的 jsPDF 库从 HTML 内容生成 pdf 文档,它运行良好。
现在我也在尝试使用这个插件添加自定义字体: https ://github.com/sphilee/jsPDF-CustomFonts-support
但是,这两个插件似乎不能很好地相互交互,当我生成 pdf 时,它会切换到标准字体。
当我单独使用自定义字体插件时,它可以工作。
这是我的代码:
var pdf = new jsPDF('p', 'pt', 'letter');
pdf.addFileToVFS('CustomFont.tff', 'base64 of .tff file');
pdf.addFont('CustomFont.tff', 'CustomFont', 'normal');
pdf.setFont('CustomFont');
var source = $('#pdf')[0];
var margins = {
top: 50,
bottom: 60,
left: 40,
width: 520
};
pdf.fromHTML(
source,
margins.left,
margins.top, {
'width': margins.width,
'elementHandlers': specialElementHandlers
},
function (dispose) {
pdf.save('Test.pdf');
}, margins);