gpt4 book ai didi

jspdf - 如何在jspdf中使用粗体自定义字体

转载 作者:行者123 更新时间:2023-12-04 17:42:05 28 4
gpt4 key购买 nike

我正在尝试使用带有 jspdf 的自定义字体但我无法将字体显示为粗体,我按照指定的步骤操作 here .
这是代码:

require ("./js/Roboto-Regular-normal.js");
require ("./js/Roboto-Regular-bold.js");
let doc = new jsPDF();

doc.setFont('Roboto-Regular');
doc.setFontSize(8);
doc.text("hello world", 50 , 50);
doc.setFontType('bold');
doc.text("Hello Bold", 50, 55);

let blob = doc.output();
const fs = require('fs');
fs.writeFile('a5.pdf', blob, 'utf8', function(err){
//Do something
});
Roboto-Regular-normal.js
(function (jsPDFAPI) {
var font = base64_font; //I didn't include this string because is too large, let me know if I should include it anyways

var callAddFont = function () {
this.addFileToVFS("Roboto-Regular-normal.ttf", font);
this.addFont("Roboto-Regular-normal.ttf", "Roboto-Regular", "normal");
};
jsPDFAPI.events.push(['addFonts', callAddFont])
})(jsPDF.API);
Roboto-Regular-bold.js:
(function (jsPDFAPI) {
var font = base64_font; //I didn't include this string because is too large, let me know if I should include it anyways

var callAddFont = function () {
this.addFileToVFS("Roboto-Regular-bold.ttf", font);
this.addFont("Roboto-Regular-bold.ttf", "Roboto-Regular", "bold");
};
jsPDFAPI.events.push(['addFonts', callAddFont])
})(jsPDF.API)
pdf 中没有任何内容显示为粗体。
我在电子中使用它,我不知道这是否会改变什么。

最佳答案

你可以像这样编辑你的 JS 文件,

doc.text("This is example paragraph", 11,13,).setFontSize(8).setFont(undefined, 'bold');

doc.text("This is example paragraph", 11,13,).setFontSize(8).setFont(undefined, 'normal');
输出在这里,
Result output

关于jspdf - 如何在jspdf中使用粗体自定义字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54032490/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com