-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex_jsmake.html
89 lines (78 loc) · 2.14 KB
/
index_jsmake.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
<!DOCTYPE html>
<html lang="zh-TW">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PDF 編輯網站</title>
<style>
body {
display: flex;
margin: 0;
padding: 0;
height: 100vh;
font-family: Arial, sans-serif;
}
#leftPane {
width: 50%;
padding: 20px;
box-sizing: border-box;
}
#rightPane {
width: 50%;
padding: 20px;
box-sizing: border-box;
background-color: #f4f4f4;
}
textarea {
width: 100%;
height: 80%;
font-size: 16px;
padding: 10px;
box-sizing: border-box;
}
button {
margin-top: 20px;
padding: 10px 20px;
font-size: 16px;
}
iframe {
width: 100%;
height: 80%;
border: none;
}
</style>
</head>
<body>
<div id="leftPane">
<textarea id="textInput" placeholder="在此輸入文字..."></textarea>
<button onclick="generatePDF()">下載 PDF</button>
</div>
<div id="rightPane">
<iframe id="pdfPreview"></iframe>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.68/pdfmake.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.68/vfs_fonts.js"></script>
<script>
const textInput = document.getElementById('textInput');
const pdfPreview = document.getElementById('pdfPreview');
textInput.addEventListener('input', updatePDF);
function updatePDF() {
const docDefinition = {
content: textInput.value
};
pdfMake.createPdf(docDefinition).getBlob(function (blob) {
const url = URL.createObjectURL(blob);
pdfPreview.src = url;
});
}
function generatePDF() {
const docDefinition = {
content: textInput.value
};
pdfMake.createPdf(docDefinition).download('document.pdf');
}
// 初始顯示空白 PDF
updatePDF();
</script>
</body>
</html>