I've created a page that pulls in various information and displays it all using a custom made document template. It's in the form of a form that can either be printed out and signed by all relevant people or, for the purposes of what I want, be converted to a PDF that can be used with electronic signatures. The signatures part is unimportant at the moment. All I want right now is to be able to convert this view to PDF.
I did some research and tried using JsPDF for this purpose.
I made the necessary script call
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
Created the view along with the button needed to perform the function
<body>
<div class="col-xl-10 mx-xl-auto"
style="max-width: 100%">
<div class="page-portrait-custom"
style="font-size: 13px;">
//Some view code here
<button id="generatePdfButton">Generate PDF</button>
//The rest of the view code here
</div>
</div>
</body>
Finally, my Javascript code
<script>
document.getElementById('generatePdfButton').addEventListener('click', function () {
// Create a new jsPDF instance
const doc = new jsPDF();
// Add content to the PDF document
const htmlContent = document.querySelector('.page-portrait-custom').outerHTML;
doc.html(htmlContent, {
callback: function (pdf) {
// Save the PDF document
pdf.save('ChangeOrderForm.pdf');
}
});
});
</script>
The button appears, but when I click it, nothing happens. I'm using Chrome for this, so I checked what was happening using the developer's tools and I got a 200 code for jspdf loading in, so that's not the problem.
When I click on the button, it doesn't seem to show anything happening. I've tried checking around to see if the file was saved in the background, but can't find anything.
I'm relatively inexperienced in this so maybe there's something fundamental I'm just unaware of that I'm missing. Regardless, any insight, advice, or suggestions would be very much appreciated.
