Property 'autoTable' does not exist on type jsPDF

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

16reactions
ashgrey91commented, Aug 24, 2020

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.

7reactions
builtbylanecommented, Oct 14, 2021

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;
Read more comments on GitHub >

github_iconTop Results From Across the Web

Property 'autoTable' does not exist on type jsPDF
The following worked for me in Angular 11, jsPDF 2.3.1, jspdf-autotable 3.5.14: import jsPDF from 'jspdf' import autoTable from ...
Read more >
Javascript – Property 'autoTable' does not exist on type jsPDF
I am using angular2 and Node JS . I have installed jspdf and jspdf-autotable both modules using npm . In angular-cli.json file, I...
Read more >
Property 'autoTable' does not exist on type jsPDF - Bountysource
I have installed jspdf and jspdf-autotable both modules using npm. and in .angular-cli.json file , I have embedded the scripts:
Read more >
jspdf-autotable - npm
Start using jspdf-autotable in your project by running `npm i ... TypeScript icon, indicating that this package has built-in type ...
Read more >
jspdf-autotable-fix-require - npm package - Snyk
Commit and submit pull request. If you don't use Prettier on autosave, please run yarn run format-all before opening your PR. Release workflow...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found