Search code examples
angularjspdfjspdf-autotable

How to use jspdf-autotable in Angular 4?


I was able to import jsPDF, however I can't use autoTable method from jspdf-autotable, not sure how to import it as a dependency of jsPDF.

import { Injectable, Component } from '@angular/core';

import * as jsPDF from 'jspdf';
import { autoTable } from 'jspdf-autotable';

@Injectable()
export class PdfService {

    constructor() {

    }

    convertJsonToPdf(columns: any, jsonData: any) {
       var doc = new jsPDF('p', 'pt');  // OK, created
       doc.autoTable(columns, jsonData); // Fails because autoTable is not in doc
    }
}

Solution

  • Extracted from discussion above, replace this line:

    import { autoTable } from 'jspdf-autotable'; 
    

    with

    import 'jspdf-autotable';