如何在Angular 7中导入jsPDF v2



我在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上的更改日志,你会看到setFontType从版本2中删除了

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