Reputation: 451
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
}
}
Upvotes: 3
Views: 7488
Reputation: 41
Instead of declaring like:
import * as jsPDF from 'jspdf';
import 'jspdf-autotable';
it is better to do this
import 'jspdf';
import 'jspdf-autotable';
declare let jsPDF;
This is how I solved the problem.
Upvotes: 2
Reputation: 8161
Extracted from discussion above, replace this line:
import { autoTable } from 'jspdf-autotable';
with
import 'jspdf-autotable';
Upvotes: 7