Text to PDF Generator
Text to PDF Generator
/* General Styling */
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 {
background: rgba(255, 255, 255, 0.1);
border-radius: 12px;
box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.3);
padding: 20px 30px;
width: 90%;
max-width: 500px;
text-align: center;
}
h1 {
font-size: 2em;
margin-bottom: 20px;
color: #fff;
}
label {
display: block;
font-size: 1.1em;
margin-top: 10px;
}
input, textarea {
width: 100%;
padding: 10px;
margin: 10px 0;
border: none;
border-radius: 8px;
font-size: 1em;
background: rgba(255, 255, 255, 0.8);
}
textarea {
height: 150px;
resize: none;
}
button {
background: #00c851;
color: #fff;
padding: 10px 20px;
font-size: 1.2em;
border: none;
border-radius: 8px;
cursor: pointer;
transition: background 0.3s ease-in-out;
}
button:hover {
background: #007e33;
}
import { jsPDF } from "jspdf";
document.getElementById("generatePdfBtn").addEventListener("click", () => {
const pdfTitle = document.getElementById("pdfTitle").value.trim();
const textInput = document.getElementById("textInput").value.trim();
if (!textInput) {
alert("Please enter some text to generate the PDF!");
return;
}
// Create a new jsPDF instance
const doc = new jsPDF();
// Add title if provided
if (pdfTitle) {
doc.setFont("Helvetica", "bold");
doc.setFontSize(16);
doc.text(pdfTitle, 10, 10);
doc.setFontSize(12);
doc.text("________________________________________", 10, 15);
}
// Add the text content
doc.setFont("Helvetica", "normal");
doc.setFontSize(12);
doc.text(textInput, 10, 30);
// Save the PDF
doc.save(pdfTitle || "document.pdf");
});