简体   繁体   English

如何在 JsPDF 中添加和设置字体?

[英]how to add and set a font in JsPDF?

I've been trying to set the Helvetica font in different ways but nothing seems to work.我一直在尝试以不同的方式设置 Helvetica 字体,但似乎没有任何效果。 I understand the addFont and setFont function but I'm having problems using them.我了解 addFont 和 setFont 函数,但我在使用它们时遇到了问题。

This is what I have:这就是我所拥有的:

doc.addFont('Helvetica', 'Helvetica', 'normal')
doc.setFont('Helvetica')

Apparently the postscript name for Helvetica is 'Helvetica' so I don't know what it could be.显然 Helvetica 的后记名称是“Helvetica”,所以我不知道它可能是什么。

you can convert your font 你可以转换你的字体

Example PTSans-normal.js示例 PTSan-normal.js

import jsPDF from 'jspdf' jsPDF - Importing fonts in React.js / ES6 style import jsPDF from 'jspdf' jsPDF - 以 React.js / ES6 风格导入字体

Using a new font使用新字体

import 'assets/fonts/PTSans-normal.js';
import jsPDF from 'jspdf';

const doc = new jsPDF();

doc.setFont('PTSans'); // set custom font
doc.setFontSize(12); // you can change size
doc.text('Hello', x, y) // and you can write your text

console.log('Show all font in jsPDF',doc.getFontList());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM