Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: doc.autoTable is not a function #984

Open
djp9192 opened this issue Jul 31, 2023 · 4 comments
Open

TypeError: doc.autoTable is not a function #984

djp9192 opened this issue Jul 31, 2023 · 4 comments
Assignees
Labels

Comments

@djp9192
Copy link

djp9192 commented Jul 31, 2023

hi, i can run autoTable with jsPDF, using autoTable up to 3.5.12 ... but when i try to use 3.5.13 up to 3.5.31, i get the error:
TypeError: doc.autoTable is not a function

Any suggestions? I'd want to make sure autoTable later versions can work too. (p.s. if we need a later jsPDF version, please let me know too). Thanks!

So, this works:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf-autotable/3.5.12/jspdf.plugin.autotable.min.js"></script>

But this doesn't:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf-autotable/3.5.31/jspdf.plugin.autotable.min.js"></script>

The same simple code is being used, it works up to autoTable 3.5.12 only:

PageModule.prototype.exportToPDFTable = function () {
var doc = new jsPDF();
doc.autoTable({
startY: 20,
head: [['ID', 'Name', 'Email', 'Country', 'IP-address']],
body: [
['1', 'Donna', '[email protected]', 'China', '211.56.242.221'],
['2', 'Janice', '[email protected]', 'Ukraine', '38.36.7.199'],
[
'3',
'Ruth',
'[email protected]',
'Trinidad and Tobago',
'19.162.133.184',
],
['4', 'Jason', '[email protected]', 'Brazil', '10.68.11.42'],
['5', 'Jane', '[email protected]', 'United States', '47.32.129.71'],
['6', 'Adam', '[email protected]', 'Canada', '18.186.38.37'],
],
});
doc.save('table.pdf');
};

@github-actions github-actions bot added the stale label Aug 26, 2023
@mmghv mmghv reopened this Sep 28, 2023
Repository owner deleted a comment from github-actions bot Sep 28, 2023
@mmghv
Copy link
Collaborator

mmghv commented Sep 30, 2023

The current version has a bug that prevents it from working with v1 of jspdf in the browser, this will be fixed in v4, for now you can use jspdf v2 from this link https://unpkg.com/jspdf@latest/dist/jspdf.umd.min.js

@mmghv mmghv added the v4 label Sep 30, 2023
@mmghv mmghv self-assigned this Oct 8, 2023
@llcostalonga
Copy link

llcostalonga commented Sep 16, 2024

Here, I´m using Vue 3 with jspdf 2.5.1 and autotable 3.8.3. and getting the error "TypeError: F.autoTable is not a function" only when I upload (firebase) or run on the firebase emulators. In dev mode works fine! Can you help me with that? Thanks.

@nrgbistro
Copy link

nrgbistro commented Oct 24, 2024

I'm getting this error even in the local dev environment. I copied the exact code from the typescript example and get TypeError: autoTable is not a function.

I'm able to get it working using doc.autoTable({...}) but I get this typescript error: Property 'autoTable' does not exist on type 'jsPDF'.

"jspdf": "^2.5.2",
"jspdf-autotable": "^3.8.4",

@astro-jets
Copy link

I get an error in NextJS that says: react-dom.development.js:20620 Uncaught TypeError: doc.autoTable is not a function
at downloadPDF.
here is my code:

 "use client"
import Image from "next/image";
import { AssetProps } from "@/types/asset";

import jsPDF from 'jspdf';

const TableTwo = ({ assets }: { assets: AssetProps[] }) => {

  const downloadPDF = (data: AssetProps[]) => {
    alert("Saving Report")
    const doc = new jsPDF();
    const arr = data.map(asset => [
      asset.name,
      asset.createdAt,
      asset.path, // Adjust if you want to display a formatted or different field
      asset.cost
    ]);

    (doc as any).autoTable({
      head: [['Asset Name', 'Created On', 'Price', 'Cost']],
      body: arr,
    });
    doc.save('assets-data.pdf');
    con
```sole.log("Doc => ", doc)
  };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants