Property 'fromHTML' does not exist on type jsPDF I am trying to use jsPDF to convert an HTML code to PDF. I've seen that the best way to do this is to use the jsPDF.fromHTML() function but when I try I get the following: Property 'fromHTML' does not exist on type 'jsPDF' I am using Angular 10 and jsPDF@2.3.1. I already tried
Asked
Active
Viewed 1.1k times
3
-
1Can you include a code sample and some more context? It's difficult to troubleshoot the issue without seeing more of how you are using it. – Dan Obregon Jul 30 '21 at 12:25
2 Answers
6
Well, that's because .fromHTML()
has been deprecated in favor of .html()
as seen in the documentation. jsPDF documentation html()

skipper
- 61
- 1
- 1
5
From my point of view this method does not exist. I see two ways:
if your html code contains the style information
const doc = new jsPDF('p', 'pt', 'a4');
const div = ...your code to get the html
await doc.html(div);
doc.save('test.pdf'); // save / download
doc.output('dataurlnewwindow'); // just open it
or if the style is defined somewhere else (as usually in angular application). you html2canvas and extract an image from canvas to add to pdf.
const doc = new jsPDF('p', 'pt', 'a4');
const div = ...your code to get the html
await html2canvas(... your element ...).then(canvas => {
// Few necessary setting options
const imgWidth = 208; // your own stuff to calc the format you want
const imgHeight = canvas.height * imgWidth / canvas.width; // your own stuff to calc the format you want
const contentDataURL = canvas.toDataURL('image/png');
doc.addImage(contentDataURL, 'PNG', 0, 0, imgWidth, imgHeight);
doc.save('test.pdf'); // save / download
doc.output('dataurlnewwindow'); // just open it

Thomas Renger
- 779
- 4
- 12
-
-
@Kevingy you are absolutely right. In this example `page` should be `doc`. I am often use `page = doc` and `page = doc.addPage()` for my better understandig, that i am adding image or content to the current page inside the document. Thanks for noticing me. – Thomas Renger Jul 04 '22 at 15:00
-
At least the method used to exist: https://codepen.io/amkid/pen/qKYwXo – Brice C. Jun 09 '23 at 05:04