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.

Answer from Kirubel 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
🌐
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.
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
I cannot use jsPDF with Angular 10
I was trying to print my page using jspdf library version 2.1.0 with Angular version 10. I've also added a question in stackoverflow and here is the link https://stackoverflow.com/questions/636... More on github.com
🌐 github.com
21
July 24, 2020
How to use jsPDF with angular 2 - Stack Overflow
you can add images,shapes,lines too. more details parall.ax/products/jspdf 2019-04-24T02:08:52.8Z+00:00 ... Old question but this is an alternative solution that I got up and running in my angular app. More on stackoverflow.com
🌐 stackoverflow.com
🌐
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 ...
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.

🌐
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:
Find elsewhere
🌐
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.
🌐
Substack
substack.com › home › post › p-151808104
jsPDF vs pdfmake: Which PDF Library Reigns Supreme for ...
November 18, 2024 - For simpler PDFs: go with jsPDF. For complex, structured PDFs: go with pdfmake. PS: Whether you're building simple invoices or complex reports, choosing the right PDF library can make all the difference in your Angular app’s performance and user experience.
🌐
GitHub
github.com › parallax › jsPDF › issues › 2892
I cannot use jsPDF with Angular 10 · Issue #2892 · parallax/jsPDF
July 24, 2020 - I was trying to print my page using jspdf library version 2.1.0 with Angular version 10. I've also added a question in stackoverflow and here is the link https://stackoverflow.com/questions/63667889/i-cannot-use-jspdf-with-angular-10 Rep...
Published   Aug 31, 2020
🌐
StackBlitz
stackblitz.com › edit › angular-jspdf-base64
Angular HTML to PDF using JSPDF - StackBlitz
Covered things - convert HTML Page to PDF and download it - Upload PDF in directory using Base64 in API
🌐
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 …
🌐
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'); } }
🌐
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
🌐
xorgeek
xorgeek.com › home › blog › pdf with jspdf and autotable
Generate PDF with jsPDF in Angular-18 - Blog - Xorgeek
April 22, 2025 - Using jsPDF and AutoTable in Angular-18 is a powerful solution for PDF generation. By addressing these challenges, I achieved a smooth, well-formatted PDF output.
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.

🌐
YouTube
youtube.com › watch
How to generate PDF with Angular and JSPDF - YouTube
In this tutorial we take a look at how to use JSPDF to generate PDF in an angular application.Here are few commands you will need to do before writing code. ...
Published   March 25, 2021