Pages

Wednesday, 27 November 2024

Text to PDF Converter Tool

Text to PDF Converter

Text to PDF Converter

© 2024 Text to PDF Converter

body { font-family: 'Arial', sans-serif; margin: 0; padding: 0; background: linear-gradient(to right, #6a11cb, #2575fc); color: #fff; display: flex; justify-content: center; align-items: center; height: 100vh; } .container { text-align: center; width: 90%; max-width: 500px; background: #ffffff33; border-radius: 10px; padding: 20px; box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3); } header h1 { margin-bottom: 20px; color: #fff; } textarea { width: 100%; height: 150px; border: none; border-radius: 5px; padding: 10px; font-size: 16px; color: #333; resize: none; outline: none; } textarea::placeholder { color: #888; } button { margin-top: 20px; background: #00c6ff; border: none; color: #fff; padding: 10px 20px; border-radius: 5px; cursor: pointer; font-size: 16px; transition: 0.3s; } button:hover { background: #007acb; } #downloadMessage { margin-top: 10px; font-size: 14px; } footer { margin-top: 20px; font-size: 12px; color: #ccc; } document.getElementById("convertBtn").addEventListener("click", function () { const { jsPDF } = window.jspdf; // Load jsPDF const text = document.getElementById("textInput").value; if (!text.trim()) { alert("Please enter some text before converting!"); return; } // Create a PDF instance const doc = new jsPDF(); const pageWidth = doc.internal.pageSize.width; const margin = 10; // Add text to the PDF with word wrapping doc.text(text, margin, 20, { maxWidth: pageWidth - margin * 2, align: "left", }); // Generate and download the PDF const fileName = "text-to-pdf.pdf"; doc.save(fileName); // Show download message const message = document.getElementById("downloadMessage"); message.textContent = `Your PDF (${fileName}) has been downloaded.`; });