如何在 Angular 7 中导入 jsPDF v2

How to import jsPDF v2 in Angular 7

我在 Angular 7 项目中使用 jsPDF。 我使用的是 jsPDF v1.3.5 并使用 import * as jsPDF from 'jspdf'; 导入。

现在我升级到 v2.0.0,升级后,我尝试了这些导入并出现了各自的错误

const { jsPDF } = require("jspdf"); //Cannot find name 'jsPDF'.
import { jsPDF } from 'jspdf';     // Error:Property 'setFontType' does not exist on type 'jsPDF

你应该使用它来导入 jsPDF

import { jsPDF } from 'jspdf'; 

如果您检查 github 上的 change log,您会看到 setFontType 已从版本 2

中删除
  • Removed APIs that were previously marked as deprecated. Namely: addHTML, fromHTML, html2pdf, addSvg, addButton, addTextField, addChoiceField, cellInitialize, setFontStyle, setFontType, clip_fixed.