Text to PDF Converter
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Text to PDF Converter</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
#pdfSettings {
margin-bottom: 20px;
}
textarea {
width: 100%;
height: 150px;
margin-bottom: 20px;
}
button {
padding: 10px;
font-size: 16px;
cursor: pointer;
}
</style>
</head>
<body>
<div id="pdfSettings">
<label for="pdfTitle">PDF Title:</label>
<input type="text" id="pdfTitle" placeholder="Enter PDF title">
<br>
<label for="pdfAuthor">PDF Author:</label>
<input type="text" id="pdfAuthor" placeholder="Enter PDF author">
</div>
<textarea id="textInput" placeholder="Enter text content..."></textarea>
<button onclick="convertToPDF()">Convert to PDF</button>
<script src="https://rawgit.com/eKoopmans/html2pdf/master/dist/html2pdf.bundle.js"></script>
<script>
function convertToPDF() {
const textInput = document.getElementById('textInput').value;
const pdfTitle = document.getElementById('pdfTitle').value || 'Converted PDF';
const pdfAuthor = document.getElementById('pdfAuthor').value || 'Anonymous';
if (textInput.trim() === '') {
alert('Please enter some text before converting to PDF.');
return;
}
const contentDiv = document.createElement('div');
contentDiv.innerHTML = textInput;
const options = {
margin: 10,
filename: `${pdfTitle}.pdf`,
image: { type: 'jpeg', quality: 0.98 },
html2canvas: { scale: 2 },
jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' },
};
html2pdf(contentDiv, options);
}
</script>
</body>
</html>