how to use jsPDF and jspdf-autotable in angular 5

后端 未结 10 859
北海茫月
北海茫月 2021-01-06 01:46

I am trying to use jsPDF and jspdf-autotable in my Angular 5.2.0 project. My package.json is below (related parts):

\"dependencies\": {
    ...
    \"jspdf\"         


        
10条回答
  •  醉梦人生
    2021-01-06 02:35

    I was able to please TypeScript like this:

    import * as jsPDF from 'jspdf';
    import 'jspdf-autotable';
    import { UserOptions } from 'jspdf-autotable';
    
    interface jsPDFWithPlugin extends jsPDF {
      autoTable: (options: UserOptions) => jsPDF;
    }
    ...
    const doc = new jsPDF('portrait', 'px', 'a4') as jsPDFWithPlugin;
    doc.autoTable({
      head: [['Name', 'Email', 'Country']],
      body: [
        ['David', 'david@example.com', 'Sweden'],
        ['Castille', 'castille@example.com', 'Norway']
      ]
    });
    

    Works in Angular 7.

提交回复
热议问题