Jspdf 2.5.1 doc.addFileToVFS 不是函数

问题描述 投票:0回答:1

我想在我的 pdf 中使用 utf8 希腊字符。我有一个基于 64 的自定义字体。

我使用addFileToVFS,但它说它不是一个函数。我也尝试过使用字体转换器,但没有用。

如果有帮助,我可以使用 CDN 作为库

fonts jspdf
1个回答
0
投票

可以在没有字体的 jsPDF 中使用“默认”PDF Greek 作为符号。然而我不推荐它,因为除非你有一个自定义的键映射器,否则清理重音反馈的间距会很慢,而且会是一场噩梦。

根据您获取首选自定义字体(作为 ttf)的方式,需要将其嵌入到页面中,然后进行转换以替换这些 PDF 符号。我们需要的是一个好的 TTF 文件中提供的 PDF 键盘数字“ToUnicode”的映射。

通常建议使用 DeJaVu 或 Noto 字体,但任何具有良好希腊字母的字体都应该可以。这里我选择了Rounded_Elegance并提交转换为JS

现在我们在 HTML 中设置文本,并将转换后的 font.js 放在同一文件夹中(还有其他几种方法),这通常是最简单的。

<!DOCTYPE html>
<HTML><head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
</head>

<body>
  <script src="jspdf.umd.js"> // Here local but can be CDN </script>
  <script src="Rounded_Elegance-normal.js"> // Here we have the font in same folder </script>

  Click me

    <script>
    window.jsPDF = window.jspdf.jsPDF;
    var doc = new jsPDF();

    //confirm stored font is to be used
    doc.addFont('Rounded_Elegance-normal.ttf', 'Greekish', 'normal'); // choose a shorter name

    doc.setFont("Greekish", "normal"); // set custom font from here onwards
    doc.setFontSize(40);
    doc.text("Γεια σας κόσμος!", 50, 50);

    doc.save("a4.pdf"); // will save the file in the current working directory
</script></body></html>

嗯,也许不像承诺的那么优雅,但它确实有效。

© www.soinside.com 2019 - 2024. All rights reserved.