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');
    }
}
Answer from GsMalhotra on Stack Overflow
🌐
npm
npmjs.com › package › jspdf
jspdf - npm
4 weeks ago - In Angular projects, externals can be defined using custom webpack builders. In React (create-react-app) projects, externals can be defined by either using react-app-rewired or ejecting. jsPDF can be imported just like any other 3rd party library.
      » npm install jspdf
    
Published   Nov 19, 2025
Version   3.0.4
Discussions

I cannot use jsPDF with Angular 10 - Stack Overflow
I was trying to print my page using jspdf library. I've tried so many solutions to get it done following examples on here and almost every Google suggestion links but I still couldn't fix it. Here is More on stackoverflow.com
🌐 stackoverflow.com
Problem with jspdf library to generate a pdf file
Read the error please More on reddit.com
🌐 r/angular
4
2
June 27, 2023
How do you generate high-quality PDFs with Angular?
Honestly microserivce HTML -> PDF is your best bet. PDF reactor hasn't failed me yet and is fully rest API based, has docker containers ready to go as well. More on reddit.com
🌐 r/Angular2
20
17
June 13, 2020
how to set top and bottom margin in .HTML using jspdf
Hi, how did you solve this? More on reddit.com
🌐 r/Angular2
1
1
December 17, 2020
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.

🌐
Eduforbetterment
eduforbetterment.com › good news › faith
Export or Open PDF in Angular using JSPDF - Education For Betterment
August 26, 2022 - Below is the full embeded code export or Open PDF in Angular using JSPDF. you can easily used in your application.
🌐
Freakyjolly
freakyjolly.com › angular-jspdf-autotable-tutorial
Angular 9|8|7 Convert Tables into PDF File using jspdf-autotable Example
April 30, 2023 - Angular tutorial to convert Tabular data into download document of PDF type. We can convert dynamic data into a table using a jsPDF Autotable library which can be converted into a PDF file to download or open in a new browser tab.
🌐
Plunker
embed.plnkr.co › plunk › bvcYhd
jsPDF example from ng-bind-html - Plunker
</b>"; $scope.click = function() { // console.log("button clicked"); // $scope.order.showPopupAddedToCart = !$scope.order.showPopupAddedToCart; 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'); }; $scope.HTMLclick = function() { console.log("starting HTMLclick"); var pdf = new jsPDF('p', 'pt', 'letter'); // source can be HTML-formatted string, or a reference // to an actual DOM element from which the text will be scraped.
Find elsewhere
🌐
DEV Community
dev.to › vidyarathna › generating-pdfs-in-angular-using-jspdf-3a6
Generating PDFs in Angular using jsPDF - DEV Community
May 29, 2024 - Integrating jsPDF into your Angular project allows you to create PDF documents dynamically within your application. By following the steps outlined above, you can set up jsPDF, create a service for PDF generation, and trigger this functionality ...
🌐
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.
Top answer
1 of 4
20

After trying so many different solutions for this issue now I've found that both the addHTML and fromHTML is depreciated in latest versions of jspdf and they are replaced with just html. For those who are seeking for a better solution to work with jspdf and Angular 10 here is what looks working and a better result that I've found so far.

To import jspdf version (2.x.x), just simply do: import { jsPDF } from 'jspdf';.

You won't need to include any of the dependencies into angular.json scripts like you would do in previous versions. And if you add scripts of jspdf or html2canvas insideindex.html, also remove them. By running npm install jspdf it also install the html2canvas which is also dynamically imported by jspdf.

import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
import { jsPDF } from 'jspdf';

.....

 @ViewChild('couponPage', { static: true }) couponPage: ElementRef;

.......

openPDF(): void {
  const DATA = this.couponPage.nativeElement;
  const doc: jsPDF = new jsPDF("p", "mm", "a4");
  doc.html(DATA, {
     callback: (doc) => {
       doc.output("dataurlnewwindow");
     }
  });
}

Though for me still using doc.html() method, it wouldn't use the css style that I used for my page.

2 of 4
3

After working with the OP for a short time on a stackblitz, it seems the main problem was that the usage of the library changed between versions 1.3.5 (the one used in the examples) to 2.1.0 (the one he was using). I am adding this answer so that it may provide a clue to future solution seekers who suffer from a similar problem.

🌐
Medium
medium.com › @juanacustodio › angular-jspdf-componente-para-imprimir-un-pdf-16a46b9dc087
Angular + jsPDF: componente para imprimir un PDF | by Juana Custodio | Medium
May 3, 2022 - Angular + jsPDF: componente para imprimir un PDF Hola! Tuve la misión de generar un cronograma en formato PDF a partir de una simulación de crédito. Decidí usar jsPDF, versión 2.5.1, y tener una …
🌐
GitHub
github.com › alpitg › angular-jspdf
GitHub - alpitg/angular-jspdf: Angular 7 + jspdf + pdf download sample
This project was generated with Angular CLI version 7.3.9. ... Pdf generate using the jspdf.
Author   alpitg
🌐
Reddit
reddit.com › r/angular › problem with jspdf library to generate a pdf file
r/angular on Reddit: Problem with jspdf library to generate a pdf file
June 27, 2023 -

Hi, I am trying to generate a pdf with jspdf and html2canvas, I have followed the documentation but when I try to download it I always get an error in console.

This is my function in the component.ts

donwloadPDF() {
// Extraemos el
const DATA: any = document.getElementById('htmlData');
const doc = new jsPDF('p', 'pt', 'a4');
const options = {
background: 'white',
scale: 3
};
html2canvas(DATA, options).then((canvas) => {
const img = canvas.toDataURL('image/PNG');
// Add image Canvas to PDF
const bufferX = 15;
const bufferY = 15;
const imgProps = (doc as any**).getImageProperties(img);**
const pdfWidth = doc.internal.pageSize.getWidth() - 2 * bufferX;
const pdfHeight = (imgProps.height * pdfWidth) / imgProps.width;
doc.addImage(img, 'PNG', bufferX, bufferY, pdfWidth, pdfHeight, undefined, 'FAST');
return doc;
}).then((docResult) => {
docResult.save(`${new Date().toISOString()}_tutorial.pdf`);
});
}

And this is the error I get on the console

Has anyone had something similar?

Thanks

🌐
jsPDF
artskydj.github.io › jsPDF › docs › index.html
jsPDF - GitHub Pages
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. You are then ready to go to use setFont-method in your code and write your UTF-8 encoded text. If you are using Webpack (including managed cli tools like angular-cli or create-react-app) you can import like this:
🌐
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'); } }
🌐
npm
npmjs.com › package › jspdf-autotable
jspdf-autotable - npm
February 26, 2025 - This jsPDF plugin adds the ability to generate PDF tables either by parsing HTML tables or by using Javascript data directly.
      » npm install jspdf-autotable
    
Published   Feb 26, 2025
Version   5.0.2
Author   Simon Bengtsson
🌐
StackBlitz
stackblitz.com › edit › angular-ivy-yfvdbk
Angular 12 Jspdf.html - StackBlitz
A angular-cli project based on rxjs, jspdf, tslib, jquery, zone.js, @angular/core, @angular/forms, @angular/common, @angular/router, @angular/compiler, @angular/animations, @angular/platform-browser and @angular/platform-browser-dynamic.