-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdf.html
132 lines (112 loc) · 3.88 KB
/
pdf.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
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="resources/html2canvas.js" type="text/javascript"></script>
<script src="resources/jspdf.js" type="text/javascript"></script>
<script>
$(document).ready(function(){
rendertry("A4");
});
function rendertry(format){
var doc_width = 210;
var doc_height = 297;
if(format=="A4"){
doc_width = 210;
doc_height = 297;
}else if(format=="Letter"){
doc_width = 215;
doc_height = 279.4;
}
var doc_width = 210;
var doc_height = 297;
var left_padding = 10;
var top_padding = 10;
//Dividing by 3.78 converts px to mm
var divwidth = $('#test').width()/3.78;
var divheight = $('#test').height()/3.78;
try{
var pdf = new jsPDF('p', 'mm', [ doc_width, doc_height]);
}catch(e){
alert(e);
}
var disclaimer = document.getElementById('test');
try{
html2canvas(disclaimer,{
scale:5
}).then(function(canvas) {
canvas.toBlob(function(blob) {
try{
var url = window.URL || window.webkitURL;
var imgSrc = url.createObjectURL(blob);
var img = new Image();
img.src = imgSrc;
img.onload = function () {
//occupied_height+= top1_height+gap;
pdf.addImage(img, left_padding,
top_padding, divwidth,divheight );
pdf.save();
};
}catch(e){
alert(e);
}
},'image/jpeg',1);
});
}catch(e){
alert(e);
}
}
</script>
</head>
<body style="">
<div >
<table id="test" border="1px solid black" cellspacing="10">
<Tr>
<Td>
a
</Td>
<Td>
b
</Td>
<Td>
c
</Td>
</Tr>
<Tr>
<Td>
a
</Td>
<Td>
b
</Td>
<Td>
c
</Td>
</Tr>
<Tr>
<Td>
a
</Td>
<Td>
b
</Td>
<Td>
c
</Td>
</Tr>
<Tr>
<Td>
a
</Td>
<Td>
b
</Td>
<Td>
c
</Td>
</Tr>
</table>
</div>
</body>
</html>