-
Notifications
You must be signed in to change notification settings - Fork 0
/
text2pdf.html
105 lines (97 loc) · 3.02 KB
/
text2pdf.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HTML Text to PDF Converter</title>
<script src="https://mrtusarrx.github.io/html2pdf-html/index.js"></script>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f9;
margin: 0;
padding: 20px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 100vh;
text-align: center;
color: #000;
}
h1 {
color: #333;
font-size: 2em;
margin-bottom: 20px;
}
textarea {
width: 100%;
max-width: 600px;
height: 200px;
padding: 10px;
font-size: 1em;
margin: 20px 0;
background-color: #fff;
border: 2px solid #ccc;
border-radius: 5px;
resize: none;
font-family: 'Courier New', Courier, monospace;
}
textarea:focus {
border-color: #666;
outline: none;
}
button {
background-color: #4CAF50;
color: white;
padding: 12px 24px;
font-size: 16px;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s ease, transform 0.2s ease;
}
button:hover {
background-color: #45a049;
transform: scale(1.05);
}
#content {
margin-top: 30px;
max-width: 600px;
padding: 20px;
background-color: #fff;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
display: none;
}
</style>
</head>
<body>
<h1>Convert HTML Text to PDF</h1>
<textarea id="htmlInput" placeholder="Paste your HTML text here"></textarea>
<button id="convert">Convert to PDF</button>
<div id="content"></div>
<script>
document.getElementById('convert').addEventListener('click', function () {
const htmlText = document.getElementById('htmlInput').value;
const contentDiv = document.getElementById('content');
if (!htmlText.trim()) {
alert("Please enter HTML text.");
return;
}
contentDiv.innerHTML = htmlText;
contentDiv.style.display = 'block';
const opt = {
margin: 0.5,
filename: 'document.pdf',
image: { type: 'jpeg', quality: 1 },
html2canvas: { scale: 2 },
jsPDF: { unit: 'in', format: 'a4', orientation: 'portrait' }
};
setTimeout(() => {
html2pdf().from(contentDiv).set(opt).save();
}, 500);
});
</script>
</body>
</html>