jsPDF-AutoTable icon indicating copy to clipboard operation
jsPDF-AutoTable copied to clipboard

Property 'autoTable' does not exist on type jsPDF

Open tbiinfotech opened this issue 9 years ago • 11 comments

I am using angular2 and Node JS. I have installed jspdf and jspdf-autotable both modules using npm. and in .angular-cli.json file , I have embedded the scripts:

"scripts": [ 
        "../node_modules/jspdf/dist/jspdf.min.js",
        "../node_modules/jspdf-autotable/dist/jspdf.plugin.autotable.js"
      ],

In my component.ts file , I have imported these files as follows:

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

In function of component.ts file I am using sample code as follows:

var columns = ["ID", "Country", "Rank", "Capital"];
        var data = [
            [1, "Denmark", 7.526, "Copenhagen"],
            [2, "Switzerland", 	7.509, "Bern"],
            [3, "Iceland", 7.501, "Reykjavík"],
            [4, "Norway", 7.498, "Oslo"],
            [5, "Finland", 7.413, "Helsinki"]
        ];
        var doc = new jsPDF();
        doc.autoTable(columns, data);
        doc.output("dataurlnewwindow");

But now when I run the node command to start app then during compilation I am getting error as Property 'autoTable' does not exist on type 'jsPDF'.

I have console the doc object and found autoTable exists there but don't know why it is creating error?

image

Can any one please suggest?

tbiinfotech avatar Nov 17 '17 05:11 tbiinfotech

Try replacing import * as autoTable from 'jspdf-autotable'; with import 'jspdf-autotable'

simonbengtsson avatar Nov 17 '17 08:11 simonbengtsson

It is working now. actually I was importing both jspdf and jspdf-autotable, that is why it was creating issue. I am using autoTableHtmlToJson() now, Can we fetch color like addHTML() in this method. actually I wants to show the colors in pdf like

image

But I am getting only text as

image

tbiinfotech avatar Nov 17 '17 14:11 tbiinfotech

I am having this same problem however, I am using angular 4.3.5 & webpack.

When using:

import * as jsPDF from 'jspdf'; import 'jspdf-autotable'

I still get the error: Property 'autoTable' does not exist on type jsPDF

Any ideas how to get this functioning?

grtn316 avatar Jan 21 '18 04:01 grtn316

I have the same issue with Angular 5 & Webpack.

MarcoBatista avatar Apr 14 '18 14:04 MarcoBatista

same here, any possible update on this issue soon ?

bbluszcz avatar Jun 27 '18 11:06 bbluszcz

Same problem here, i'm use 1.1.31

alciomarhollanda avatar Jul 11 '18 20:07 alciomarhollanda

Any update on this facing same with angular 5 and webpack and "jspdf": "^1.4.1", "jspdf-autotable": "^2.3.5"

pranjal-card avatar Sep 26 '18 05:09 pranjal-card

I have the same issue with Angular 10

bessam-haj-salem avatar Jul 31 '20 17:07 bessam-haj-salem

instead of doc.autoTable, For angular, you can use, autoTable(doc, { html: '#html-table-id',startY: 30, });

" You can also use the exported autoTable method. This works better with typescript and alternative jsPDF versions.

import jsPDF from 'jspdf' // import jsPDF = require('jspdf') // // typescript without esModuleInterop flag // import jsPDF from 'yworks-pdf' // using yworks fork // import jsPDF from 'jspdf/dist/jspdf.node.debug' // for nodejs import autoTable from 'jspdf-autotable'

const doc = new jsPDF() autoTable(doc, { html: '#my-table' }) doc.save('table.pdf') " The above is from the link https://github.com/simonbengtsson/jsPDF-AutoTable#installation

but I am not sure how to get the lastAutoTable.finalY position in typescript.

ashgrey91 avatar Aug 24 '20 16:08 ashgrey91

instead of doc.autoTable, For angular, you can use, autoTable(doc, { html: '#html-table-id',startY: 30, });

" You can also use the exported autoTable method. This works better with typescript and alternative jsPDF versions.

import jsPDF from 'jspdf' // import jsPDF = require('jspdf') // // typescript without esModuleInterop flag // import jsPDF from 'yworks-pdf' // using yworks fork // import jsPDF from 'jspdf/dist/jspdf.node.debug' // for nodejs import autoTable from 'jspdf-autotable'

const doc = new jsPDF() autoTable(doc, { html: '#my-table' }) doc.save('table.pdf') " The above is from the link https://github.com/simonbengtsson/jsPDF-AutoTable#installation

but I am not sure how to get the lastAutoTable.finalY position in typescript.

@ashgrey91 you can just convert doc to an any type like so (doc as any).lastAutoTable. Not ideal, but it'll get it working.

johnEthicalTechnology avatar Apr 27 '21 00:04 johnEthicalTechnology

assuming you have @types/jspdf installed...

import { jsPDF } from 'jspdf';
import 'jspdf-autotable';
import { UserOptions } from 'jspdf-autotable';

interface jsPDFCustom extends jsPDF {
    autoTable: (options: UserOptions) => void;
}

const doc = new jsPDF() as jsPDFCustom;

builtbylane avatar Oct 14 '21 03:10 builtbylane