Txt to PDF in HTML

php Copy code Text to PDF Generator

Text to PDF Generator

JavaScript Code: javascript Copy code const generatePdfBtn = document.getElementById('generate-pdf-btn'); generatePdfBtn.addEventListener('click', () => { const textInput = document.getElementById('text-input').value.trim(); if (!textInput) return; const doc = new jsPDF(); doc.text(textInput, 10, 10); doc.save('text-to-pdf.pdf'); }); In this example, we use the jsPDF library to generate a PDF document. When the "Generate PDF" button is clicked, we retrieve the text input value, create a new jsPDF instance, and add the text input to the PDF document. Finally, we save the PDF document with the filename "text-to-pdf.pdf". This code is responsive because we use the viewport meta tag in the head section of the HTML to ensure that the webpage fits the screen of the device being used to access it

Comments

Popular Posts