You have to use as following. I had the same question for a while, but after asking the question from the developers, I found that you have to use the instance of jsPdf() as an argument of autoTable() function. Rest goes as the documentation of jsdpf.

import { Component, OnInit } from '@angular/core';
import * as jsPDF from 'jspdf';
import autoTable from 'jspdf-autotable';

const doc = new jsPDF();

const columns = [['First Column', 'Second Column', 'Third Column']];
const data = [
['Data 1', 'Data 2', 'Data 3'],
['Data 1', 'Data 2', 'Data 3']
];

 autoTable(doc, {
      head: columns,
      body: data,
      didDrawPage: (dataArg) => { 
       doc.text('PAGE', dataArg.settings.margin.left, 10);
      }
 }); 

doc.save('table.pdf');

Example
Source Codes
https://codesandbox.io/s/currying-pine-wjp1g?file=/src/app/app.component.ts
Live Demo
https://wjp1g.csb.app/

Answer from Don Dilanga on Stack Overflow
🌐
npm
npmjs.com › package › jspdf
jspdf - npm
The fontconverter will create a js-file with the content of the provided ttf-file as base64 encoded string and additional code for jsPDF. You just have to add this generated js-File to your project.
      » npm install jspdf
    
Published   Nov 19, 2025
Version   3.0.4
🌐
Freakyjolly
freakyjolly.com › angular-jspdf-autotable-tutorial
Angular 9|8|7 Convert Tables into PDF File using jspdf-autotable Example
April 30, 2023 - In this article, we will learn How to install and use the jspdf-autotable in the Angular 8/9 project to create a PDF document of JSON object data in the form of a table.
🌐
GitHub
github.com › parallax › jsPDF › issues › 2605
How can we use jsPDF in a web worker from Angular 8 app? · Issue #2605 · parallax/jsPDF
There is any way to use web workers for parallelism when generating multiple PDF pages in separate threads(in web workers) in an Angular applications ? Because when we try we received an error like 'Uncaught ReferenceError: window is not defined' ! Is this because of the limitation of web workers when using DOM elements? It look like with simple JavaScript jsPDF can be used in web worker : https://github.com/jstarcher/webworker_jspdf_example/tree/master/js How can we do the same in Angular with TypeScript ?
Published   Oct 23, 2019
Author   sorryb
🌐
StackBlitz
stackblitz.com › edit › angular-jspdf
Angular Jspdf - StackBlitz
Starter project for Angular apps that exports to the Angular CLI
🌐
DEV Community
dev.to › vidyarathna › generating-pdfs-in-angular-using-jspdf-3a6
Generating PDFs in Angular using jsPDF - DEV Community
May 29, 2024 - In modern web applications, generating PDF documents can be an essential feature for reports, invoices, and more. In this article, we will explore how to integrate and use jsPDF, a popular JavaScript library, in an Angular application to generate PDF files dynamically.
🌐
Plunker
embed.plnkr.co › 5yYBBfv45Um78Md7EMv3
angular2 jsPDF example - Plunker
import { Component } from '@angular/core'; declare let jsPDF; @Component({ selector: 'my-app', template: `<h1>JSON to PDF app</h1> <div class="container" id="div1"> <button id="create" (click)="convert('base')">Create file</button> <button id="create" (click)="convert('horizontal')">Create file with horizontal table</button> </div> ` }) export class AppComponent { cols: Array<any> = [{ title: "Details", dataKey: 'details' }, { title: "Values", dataKey: 'values' }]; optionsContainer = { base: {}, horizontal: { drawHeaderRow: () => false, columnStyles: { details: {fillColor: [41, 128, 185], text
Find elsewhere
Top answer
1 of 5
84

I have done it, after doing lot of R&D , their are few steps to follow as below : Install :

npm install jspdf --save

typings install dt~jspdf --global --save

npm install @types/jspdf --save

Add following in angular-cli.json:

"scripts": [ "../node_modules/jspdf/dist/jspdf.min.js" ]

html:

<button (click)="download()">download </button>

component ts:

import { Component, OnInit, Inject } from '@angular/core';
import * as jsPDF from 'jspdf'
@Component({
  ...
  providers: [
    { provide: 'Window',  useValue: window }
  ]
})
export class GenratePdfComponent implements OnInit {

  constructor(
    @Inject('Window') private window: Window,
    ) { }

  download() {

        var doc = new jsPDF();
        doc.text(20, 20, 'Hello world!');
        doc.text(20, 30, 'This is client-side Javascript, pumping out a PDF.');
        doc.addPage();
        doc.text(20, 20, 'Do you like that?');

        // Save the PDF
        doc.save('Test.pdf');
    }
}
2 of 5
11

Old question but this is an alternative solution that I got up and running in my angular app. I ended up modifying this jsPDF solution to work without using the ionic/cordova CLI.

npm install jspdf --save
npm install @types/jspdf --save
npm install html2canvas --save
npm install @types/html2canvas --save

Add an id to whichever div contains the content you want to generate the PDF

<div id="html2Pdf">your content here</div>

Import the libraries

import * as jsPDF from 'jspdf';
import * as html2canvas from 'html2canvas';

Add the method for generating the PDF

generatePdf() {
    const div = document.getElementById("html2Pdf");
    const options = {background: "white", height: div.clientHeight, width: div.clientWidth};

    html2canvas(div, options).then((canvas) => {
        //Initialize JSPDF
        let doc = new jsPDF("p", "mm", "a4");
        //Converting canvas to Image
        let imgData = canvas.toDataURL("image/PNG");
        //Add image Canvas to PDF
        doc.addImage(imgData, 'PNG', 20, 20);

        let pdfOutput = doc.output();
        // using ArrayBuffer will allow you to put image inside PDF
        let buffer = new ArrayBuffer(pdfOutput.length);
        let array = new Uint8Array(buffer);
        for (let i = 0; i < pdfOutput.length; i++) {
            array[i] = pdfOutput.charCodeAt(i);
        }

        //Name of pdf
        const fileName = "example.pdf";

        // Make file
        doc.save(fileName);

    });
}

I found this solution worked well for my web app and was beneficial as I have control over when I want to generate the PDF (after receiving data asynchronously). As well, I didn't need install any libraries globally.

🌐
C# Corner
c-sharpcorner.com › article › html-to-pdf-using-jspdf-in-angular
HTML To PDF Using JSPDF In Angular
February 13, 2023 - import { Component, OnInit } from "@angular/core"; import jsPDF from "jspdf"; import "jspdf-autotable"; @Component({ selector: "my-app", templateUrl: "./app.component.html", styleUrls: ["./app.component.css"] }) export class AppComponent implements OnInit { ngOnInit() {} getBase64Image(img) { var canvas = document.createElement("canvas"); console.log("image"); canvas.width = img.width; canvas.height = img.height; var ctx = canvas.getContext("2d"); ctx.drawImage(img, 0, 0); var dataURL = canvas.toDataURL("image/png"); return dataURL; } download() { let doc = new jsPDF(); doc.autoTable({html: '#table'}); doc.output('datauri','test.pdf'); } }
🌐
Nutrient
nutrient.io › blog › sdk › how to generate pdfs using angular
Generating PDFs in Angular with jsPDF and Nutrient Web SDK
July 16, 2025 - Here, the code defines an Angular component named PdfGeneratorComponent that generates a PDF document with text and a table when a button is clicked. It uses the jsPDF library for PDF creation and jspdf-autotable for building tables within the PDF.
🌐
Folkstalk
folkstalk.com › tech › jspdf-html-to-pdf-angular-8-with-code-examples
Jspdf Html To Pdf Angular 8 With Code Examples
What is jsPDF? jsPDF is an open-source ... various ways of PDF generation.29-Apr-2015 · Html to pdf using pdfmake and html-to-pdfmake package · Step 1 : Create an angular app....
🌐
Shanegibney
shanegibney.com › shanegibney › angular2-and-jspdf-file-generation
Angular2+ jsPDF and html2canvas File Generation – Tech. Notes
generatePDF(){ var doc = new jsPDF(); doc.text(50,90,this.problems.length.toString()); doc.text(50,100,'page 1') doc.addPage(); doc.text(50,100,'page 2') html2canvas(document.getElementById('graph')).then(function(canvas) { var img = canvas.toDataURL("image/png"); doc.addImage(img, 'JPEG', ...
🌐
Transformacaodigital
home.transformacaodigital.com › ct8t2f › jspdf-angular-6-example.html
Jspdf angular 6 example
This example points to the minified version 1. In this article, you will see how to export a pdf file in angular 8 using pdfmake. com/jspdf-autotable param 6 -> height of the image 16 Sep 2018 Convert HTML To PDF Using Angular 6 In the end, I found a JavaScript named JSPDF.
🌐
GitHub
gist.github.com › Mustafa-Omran › c38bf7c06bd9e995031e68e1735a6721
Angular - Export Multiple Pages with PDF format - Using jsPDF && html2canvas packages · GitHub
Angular - Export Multiple Pages with PDF format - Using jsPDF && html2canvas packages · Raw · export-to-pdf.html · This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Top answer
1 of 6
22

What I found worked was adding:

<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.js"></script>

to the index.html file (it could presumably be elsewhere).

I then used:

const elementToPrint = document.getElementById('foo'); //The html element to become a pdf
const pdf = new jsPDF('p', 'pt', 'a4');
pdf.addHTML(elementToPrint, () => {
    doc.save('web.pdf');
});

Which no longer uses html2canvas in the code.
You can then remove the following import:

import * as html2canvas from 'html2canvas';
2 of 6
9

In case someone prefer not to use cdn scripts & would like to use a more (angular) way, this worked for me in Angular 6:

Using this way will give you better support & autocomplete in the editor & will help you avoid depending on cdn scripts (if you wanna avoid them, like me)

Based on the excellent answer here & since it was hard for me to find that answer, I am re-sharing what was stated in it & helped me use jsPDF in Angular 6 (all credit goes to the original author of this answer)

You should run these cmds:

npm install jspdf --save

typings install dt~jspdf --global --save

npm install @types/jspdf --save

Add following in angular-cli.json:

"scripts": [ "../node_modules/jspdf/dist/jspdf.min.js" ]

html:

<button (click)="download()">download </button>

component ts:

import { Component, OnInit, Inject } from '@angular/core';
import * as jsPDF from 'jspdf'
@Component({
  ...
  providers: [
    { provide: 'Window',  useValue: window }
  ]
})
export class GenratePdfComponent implements OnInit {

  constructor(
    @Inject('Window') private window: Window,
    ) { }

  download() {

        var doc = new jsPDF();
        doc.text(20, 20, 'Hello world!');
        doc.text(20, 30, 'This is client-side Javascript, pumping out a PDF.');
        doc.addPage();
        doc.text(20, 20, 'Do you like that?');

        // Save the PDF
        doc.save('Test.pdf');
    }
}
🌐
GeeksforGeeks
geeksforgeeks.org › angularjs › how-to-export-data-as-pdf-in-angular
How To Export Data As PDF in Angular? - GeeksforGeeks
July 23, 2025 - "dependencies": { "@angular/animations": "^18.2.0", "@angular/common": "^18.2.0", "@angular/compiler": "^18.2.0", "@angular/core": "^18.2.0", "@angular/forms": "^18.2.0", "@angular/platform-browser": "^18.2.0", "@angular/platform-browser-dynamic": "^18.2.0", "@angular/router": "^18.2.0", "html2canvas": "^1.4.1", "jspdf": "^2.5.2", "rxjs": "~7.8.0", "tslib": "^2.3.0", "zone.js": "~0.14.10" } It will add a simple HTML template with button to trigger PDF creation and a section with content that we will export as PDF. ... <!-- app.component.html --> <div class="container"> <h1>GeeksforGeeks</h1> <