<!DOCTYPE html>
<html>
<head>
<title>Text to PDF Converter</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f2f2f2;
}
.container {
max-width: 600px;
margin: 0 auto;
padding: 20px;
background-color: #fff;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
h1 {
text-align: center;
color: #333;
}
textarea {
width: 100%;
height: 200px;
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
resize: vertical;
}
.btn-container {
text-align: center;
margin-top: 20px;
}
.btn {
display: inline-block;
padding: 10px 20px;
background-color: #4caf50;
color: #fff;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
text-decoration: none;
transition: background-color 0.3s ease;
}
.btn:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<div class="container">
<h1>Text to PDF Converter</h1>
<textarea id="textInput" placeholder="Enter your text here..."></textarea>
<div class="btn-container">
<button class="btn" onclick="convertToPdf()">Convert to PDF</button>
</div>
</div>
<script>
function convertToPdf() {
var text = document.getElementById('textInput').value;
// Create a new PDF document
var doc = new jsPDF();
// Set font size and style
doc.setFontSize(12);
doc.setFontStyle('normal');
// Split text into paragraphs
var paragraphs = text.split('\n');
// Add each paragraph to the PDF
paragraphs.forEach(function (paragraph, index) {
if (index > 0) {
doc.addPage(); // Add a new page for each paragraph
}
doc.text(20, 20, paragraph);
});
// Save the PDF
doc.save('converted_text.pdf');
}
</script>
</body>
</html>
Documentation
Step 1:- Open txt file from the folder for code
Step 2:- Copy all code
Step 3:- Open your website dashboard or blog
Step 4:- Add HTML element
Step 5:- Paste all code in your html element
Step 6:- Save file
Done you are successfully Pasted code in your website.
No comments:
Post a Comment