-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.html
174 lines (171 loc) · 4.05 KB
/
index.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Test</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<style>
.page {
height: 700px;
}
.page img {
max-width: 100%;
margin-top: 50px;
}
.page-1 {
background: rgba(255, 0, 0, 0.5);
}
.page-2 {
/* height: 200px; */
background: rgba(0, 0, 255, 0.5);
}
.page-3 {
/* height: 200px; */
background: rgba(255, 255, 0, 0.5);
}
.page-4 {
background: rgba(255, 0, 0, 0.5);
}
.page-5 {
/* height: 200px; */
background: rgba(0, 0, 255, 0.5);
}
table {
width: 100%;
}
th, td {
width: 100px;
}
table, th, td {
border: 1px solid black;
}
tr {
height: 100px;
}
</style>
<script src="https://unpkg.com/jspdf@latest/dist/jspdf.umd.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/html2canvas.min.js"></script>
</head>
<body>
<button id="print-btn" class="btn btn-success m-5">生成PDF</button>
<div id="page" style="width: 595.28px;color: black;background: white;">
<!--1st-->
<div id="first">
<div class="page page-1">
<h3>Test page 1</h3>
<p>This is an page for testing 1, This is an page for testing 1, This is an page for testing 1, This is an page for testing 1</p>
</div>
<div class="page page-2">
<h3>Test page 2</h3>
<p>
<img src="./content.jpg" crossOrigin="Anonymous" />
</p>
</div>
<div class="page page-3">
<h3>Test page 3</h3>
<p>This is an page for testing 3</p>
</div>
<div class="grid grid-cols-2">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
</div>
</div>
<!--2nd-->
<div id="second">
<div class="page page-4">
<h3>Test page 4</h3>
<p>This is an page for testing 3</p>
</div>
<div class="page page-5">
<h3>Test page 5</h3>
<p>
This is an page for testing 5
<p>
<img src="./content.jpg" />
</p>
</p>
</div>
<table>
<thead>
<tr>
<th>Title3</th>
<th>Title2</th>
<th>Title2</th>
</tr>
</thead>
<tbody>
<tr>
<td>Content1</td>
<td>Content1</td>
<td>Content1</td>
</tr>
<tr>
<td>Content1</td>
<td>Content1</td>
<td>Content1</td>
</tr>
<tr>
<td>Content1</td>
<td>Content1</td>
<td>Content1</td>
</tr>
</tbody>
</table>
</div>
</div>
<script src="dist/jspdf-html2canvas.js"></script>
<script>
document.getElementById('print-btn').addEventListener('click', function() {
// one page
// html2PDF(document.getElementById('page'), {
// jsPDF: {
// format: 'b5',
// },
// imageType: 'image/png',
// margin: {
// top: 30,
// right: 10,
// bottom: 30,
// left: 10,
// },
// watermark: {
// src: './test.png',
// ratio: 0.5
// },
// watermark({ pdf }) {
// pdf.setTextColor('#ddd');
// pdf.text(50, pdf.internal.pageSize.height - 30, 'Watermark');
// },
// })
// multi page
html2PDF([
document.getElementById('first'),
document.getElementById('second'),
], {
// jsPDF: {
// format: 'b5',
// },
margin: {
top: 30,
right: 10,
bottom: 30,
left: 10,
},
html2canvas: {
scrollY: 0,
scrollX: 0,
},
success(pdf) {
console.log(this);
},
// autoResize: true,
})
});
</script>
</body>
</html>