我可能在我的代码中遇到了一个错误,但我还不确定。我正在尝试在我的Vue应用程序中创建一个带有自定义字体的PDF文件。我下载了该字体并使用在Github存储库中提供的/fontconverter/fontconverter.html将其转换为base64。我创建了一个名为“fonts”的新文件夹。在该文件夹中,我包含了自定义字体的.ttf文件和来自字体转换器的.js文件。接下来,我创建了一个名为downloadPdf()
的方法,它看起来像这样:
const doc = new jsPDF()
doc.setFontSize(28);
doc.text(20, 30, 'This is the default font.')
doc.setFont('courier')
doc.setFontType('normal')
doc.text(20, 60, 'This is courier normal.')
//This does not seem to solve the problem.
//Also, this method is already included at the bottem of the 'Roboto-Regular-normal.js' file
doc.addFileToVFS("./fonts/Roboto-Regular.ttf", './fonts/Roboto-Regular-normal.js');
doc.addFont("./fonts/Roboto-Regular.ttf", "Roboto", "normal");
doc.setFont("Roboto");
doc.text("Reinier van der Galien", 20, 90);
console.log(doc.getFontList());
doc.save("customFonts.pdf");
这将创建PDF,并使用自定义字体,所以可以正常工作。但是,在控制台中仍会出现以下错误: “jsPDF PubSub错误:没有字体的Unicode cmap错误:没有字体的Unicode cmap” 还有: “jsPDF PubSub错误:无法读取未定义属性'widths'” addFileToVFS方法似乎不起作用。需要帮助。