eKoopmans / html2pdf.js

Client-side HTML-to-PDF rendering using pure JS.
MIT License
4.12k stars 1.39k forks source link

How to use html2pdf.js without NPM or any other package manager. #626

Open sajidmanzoor10p opened 1 year ago

sajidmanzoor10p commented 1 year ago

Hello

How to use How to use html2pdf.js without NPM or any other package manager. I am working on a legacy project and need to use html2pdf.js with jQuery or Javascript. Please confirm how can I do that.

I tried adding dependencies before html2pdf.js but it giving exception.

html2pdf.min.js:2 Uncaught TypeError: Cannot read properties of undefined (reading 'jsPDF')
    at ./src/plugin/jspdf-plugin.js (html2pdf.min.js:2:2378)
    at r (html2pdf.min.js:2:72332)
    at html2pdf.min.js:2:72910
    at html2pdf.min.js:2:73107
    at html2pdf.min.js:2:73120
    at html2pdf.min.js:2:303
    at html2pdf.min.js:2:328

Please confirm how can I use it without NPM.

Thanks

jonXmack commented 1 year ago

https://github.com/eKoopmans/html2pdf.js#cdn

<script src="https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.10.1/html2pdf.bundle.min.js" integrity="sha512-GsLlZN/3F2ErC5ifS5QtgpiJtWd43JWSuIgh7mbzZ8zBps+dvLusV+eNQATqgA/HdeKFVgA5v3S/cIrLF7QnIg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

sajidmanzoor10p commented 1 year ago

@jonXmack What will be solution if someone don't want to use CDN due to any reason?

jonXmack commented 1 year ago

Download the zip and use the bundle from the dist folder. If you don't want to download the zip you could just copy the contents of the bundle file from the repo and then create a js file within your project.