58
Views
9
Comments
How to convert HTML content to PDF using javascript?
Application Type
Reactive

Hi,


I want to convert HTML content in PDF format. I am trying to achieve this using javascript. There is a library named jspdf in javascript that fulfills this requirement. But I am not able to use that library. How should I import/install/include jspdf library in javascript code. 

I am providing the code that I have written on click of a button. It's throwing jspdf not found error : 

var script = document.createElement('script');

script.src = "https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js";

script.onload = function() {    

var pdf = new jsPDF();    

pdf.text('Hello world!',10, 10);    

pdf.save('hello.pdf');

};

document.head.appendChild(script);


Let me know if the logic I am trying to implement is possible by anyway or is there any another method that I can use.

Thank you !

 

UserImage.jpg
Anjali Choudhary

Hi @Ibtesam Shaikh ,

You can use this Link 

Thanks

UserImage.jpg
Ibtesam Shaikh

Thanks @Harshit Nag, it's working for me!

UserImage.jpg
Ibtesam Shaikh

Thanks, I'll check.

UserImage.jpg
Neha Bhimsaria

Hello  Ibtesam Shaikh , 

I have attached an oml file for your reference, 
I think it is the same approach you are using but with different JS. 

The JS which needs to be uploaded :

Javascript to download

Please look into it. 

Regards 
Neha 

TestScreen.oml
UserImage.jpg
Ibtesam Shaikh

Thanks, I'll check.

UserImage.jpg
Neha Bhimsaria

Please mark as a solution if you got one. 

2025-04-17 05-42-16
Ajit Kurane

Hi,

I have attached an oml file for your reference.

Please check if its matching your use case.

Thanks.

AjPdfDemo.oml
UserImage.jpg
Ibtesam Shaikh

Thanks, I'll check.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.