質問編集履歴

4

内容の修正

2019/02/08 00:29

投稿

syncrock
syncrock

スコア209

test CHANGED
File without changes
test CHANGED
@@ -62,7 +62,7 @@
62
62
 
63
63
  var pageHeight = 295;
64
64
 
65
- var imgHeight = ((canvas.height+701) * imgWidth)/canvas.width;
65
+ var imgHeight = ((canvas.height) * imgWidth)/canvas.width;
66
66
 
67
67
  var heightLeft = imgHeight;
68
68
 

3

内容修正

2019/02/08 00:29

投稿

syncrock
syncrock

スコア209

test CHANGED
File without changes
test CHANGED
@@ -203,3 +203,7 @@
203
203
  また、項目6の日付が「~」とかぶってます。
204
204
 
205
205
  IE11ではなぜか罫線が出ませんでした。
206
+
207
+ (それは本来のページでは起こっていませんので、cssの問題があるのだと思いますが。)
208
+
209
+ また、html2canvasは1.0.0-alpha12です。

2

内容の修正

2019/02/06 07:13

投稿

syncrock
syncrock

スコア209

test CHANGED
File without changes
test CHANGED
@@ -27,3 +27,179 @@
27
27
  崩れがあるかどうか確認ではなく、使用されたことがある方で崩れた経験を持ち、
28
28
 
29
29
  それを回避した経験がある方がいればと思い質問させて頂きました。
30
+
31
+
32
+
33
+
34
+
35
+ --
36
+
37
+ 以下にサンプルコードを載せます。
38
+
39
+ ```html
40
+
41
+ <!DOCTYPE html>
42
+
43
+ <html lang="ja">
44
+
45
+ <head>
46
+
47
+ <meta charset="UTF-8">
48
+
49
+ <script src="https://cdn.polyfill.io/v2/polyfill.min.js"></script>
50
+
51
+ <script src="https://unpkg.com/jspdf@latest/dist/jspdf.min.js"></script>
52
+
53
+ <script src="html2canvas.min.js"></script>
54
+
55
+ <script>
56
+
57
+ function downloadImage() {
58
+
59
+ html2canvas(document.body).then(function(canvas) {
60
+
61
+ var imgWidth = 210;
62
+
63
+ var pageHeight = 295;
64
+
65
+ var imgHeight = ((canvas.height+701) * imgWidth)/canvas.width;
66
+
67
+ var heightLeft = imgHeight;
68
+
69
+ var imgData = canvas.toDataURL('image/png');
70
+
71
+ var doc = new jsPDF('p', 'mm');
72
+
73
+ var position = 0;
74
+
75
+ doc.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight);
76
+
77
+ heightLeft -= pageHeight;
78
+
79
+ while (heightLeft >= 0) {
80
+
81
+ position = heightLeft - imgHeight;
82
+
83
+ doc.addPage();
84
+
85
+ doc.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight);
86
+
87
+ heightLeft -= pageHeight;
88
+
89
+ }
90
+
91
+ doc.save('file.pdf');
92
+
93
+ });
94
+
95
+ }
96
+
97
+ </script>
98
+
99
+ <style>
100
+
101
+ *{
102
+
103
+ font-family:Geneva, Verdana, sans-serif;
104
+
105
+ }
106
+
107
+ </style>
108
+
109
+ </head>
110
+
111
+ <body style="background-color:#EDF7FF;">
112
+
113
+ <input id="downloadImageButton" type="button" value="画像保存" onclick="downloadImage();"/>
114
+
115
+ <div style="width:910px">
116
+
117
+ <table border="1" cellspacing="0" cellpadding="0" style="width:100%;text-align:center">
118
+
119
+ <tr>
120
+
121
+ <th style="width:40px">No.</th>
122
+
123
+ <th style="width:80px"><a href="#">項目1</a></span></th>
124
+
125
+ <th style="width:80px"><a href="#">項目2</a></span></th>
126
+
127
+ <th style="width:80px"><a href="#">項目3</a></span></th>
128
+
129
+ <th style="width:80px">項目4</th>
130
+
131
+ <th style="width:80px">項目5</th>
132
+
133
+ <th style="width:80px">項目6</th>
134
+
135
+ <th style="width:80px">項目7</th>
136
+
137
+ <th style="width:80px">項目8</th>
138
+
139
+ <th style="width:80px">項目9</th>
140
+
141
+ </tr>
142
+
143
+ <tr>
144
+
145
+ <td><label>1</label></td>
146
+
147
+ <td><label>item1</label></td>
148
+
149
+ <td><label>item2</label></td>
150
+
151
+ <td><label>item3</label></td>
152
+
153
+ <td><label>item4</label></td>
154
+
155
+ <td><label>item5</label></td>
156
+
157
+ <td><label>2019/04/01</label>~<br><label>2020/03/31</label></td>
158
+
159
+ <td><label>ああああああああああああああああああああああああああああああ</label></td>
160
+
161
+ <td><label></label></td>
162
+
163
+ <td><a href="#">item6</a></td>
164
+
165
+ </tr>
166
+
167
+ <tr>
168
+
169
+ <td><label>2</label></td>
170
+
171
+ <td><label>item1</label></td>
172
+
173
+ <td><label>item2</label></td>
174
+
175
+ <td><label>item3</label></td>
176
+
177
+ <td><label>item4</label></td>
178
+
179
+ <td><label>item5</label></td>
180
+
181
+ <td><label>2019/04/01</label>~<br><label>2020/03/31</label></td>
182
+
183
+ <td><label>ああああああああああああああああああああああああああああああ</label></td>
184
+
185
+ <td><label></label></td>
186
+
187
+ <td><a href="#">item6</a></td>
188
+
189
+ </tr>
190
+
191
+ </table>
192
+
193
+ </div>
194
+
195
+ </body>
196
+
197
+ </html>
198
+
199
+ ```
200
+
201
+ 例えば、これの場合FireFoxだと項目1~項目3のリンクの下線が文字に被っています。
202
+
203
+ また、項目6の日付が「~」とかぶってます。
204
+
205
+ IE11ではなぜか罫線が出ませんでした。

1

編集・追記依頼の対応

2019/02/06 07:06

投稿

syncrock
syncrock

スコア209

test CHANGED
File without changes
test CHANGED
@@ -13,3 +13,17 @@
13
13
  ・cssなど意識せずとも画面の内容をキャプチャしPDF化してくれていますが、一部cssに崩れがあります。
14
14
 
15
15
  どうも、A4のサイズに合わせたために横幅がギュッとなってるような感じなのですが、回避策などご存じないでしょうか。
16
+
17
+
18
+
19
+ ---
20
+
21
+ >問題の再現ができないことには「崩れがある」「回避策はないか」と書かれても回答するために最も必要な情報がありません。
22
+
23
+ すいません、html文は載せることができません。
24
+
25
+ scriptは参考にしているところの通りです。
26
+
27
+ 崩れがあるかどうか確認ではなく、使用されたことがある方で崩れた経験を持ち、
28
+
29
+ それを回避した経験がある方がいればと思い質問させて頂きました。