This repository has been archived by the owner on Aug 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWord File Creator.html
114 lines (99 loc) · 3.86 KB
/
Word File Creator.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
<!DOCTYPE html>
<html>
<head>
<script src="jquery-3.4.1.min.js"></script>
<script src="Chart.min.js"></script>
<script src="canvas-toBlob.js"></script>
<style>
#wrapper {
max-width: 450px;
margin: 50px auto;
}
#download_button{
border: 1px solid gold;
text-decoration:none;
color: cornflowerblue;
border-radius: 30px 20px;
padding: 10px;
}
</style>
</head>
<body>
<script>
//Parameters: (x-axis,y-axis,title,diseaseName,datesOfRecord,comment)
// var y_axis = ["January","February","March","April","May","June","July","August","September","October"];
// var x_axis = [86,114,106,106,107,111,133,221,783,2478];
// var title = "Recorded Monthly Incidence of Infectious Diseases for Academic Year 2018-2019";
// var diseaseName = "URTI";
// var datesOfRecord = 'August 14, 2018-April 24, 2019';
// var comment = 'Laughter is the best medicine in life, and browsing for memes is guaranteed to brighten your day by putting a big beautiful smile on your face. No need to go to the doctor, you will die anyway.';
function createDocx(x,y,t,dn,dor,c){
var canvas = document.createElement('canvas');
canvas.id='myChart';
var wrapper = document.createElement('div');
wrapper.id='wrapper';
wrapper.style.width="450px";
wrapper.appendChild(canvas);
document.body.appendChild(wrapper);
wrapper.style.visibility="hidden";//make the element invisible
var ctx = document.getElementById("myChart");
var myChart = new Chart(ctx, {
type: 'bar',
options: {
animation: {
onComplete: function(){
var url_base64jp = document.getElementById("myChart").toDataURL("image/jpg");
console.log(url_base64jp);//test
//doc file code made with brute force, extracting ms word, and divine intervention
var htmlString =
'<html xmlns:"http://www.w3.org/TR/REC-html40" xmlns:office="urn:schemas-microsoft-com:office:office" xmlns:word="urn:schemas-microsoft-com:office:word"> <head><xml><word:WordDocument><word:View>Print</word:View><word:Zoom>90</word:Zoom><word:DoNotOptimizeForBrowser/></word:WordDocument></xml></head>'+
'<body style="font-family:times new roman; font-size:12pt;">'+
'<div id="header" style="width:627px; text-align:left;"><img src="pshs-logo.png" width="627" height="89"/></div><br><br><br>'+
'<div id="title" style="text-align:center; font-size:16pt; font-weight:bold;">'+title+'</div><br>'+
'<div id="datesOfRecord" style="text-align:center; font-style:italic;">(Records as of '+datesOfRecord+')</div><br><br>'+
'<div id="diseaseName">'+diseaseName+'</div><br><br>'+
'<div id="graph" style="text-align:center;"><img src="'+diseaseName+'.jpg"/></div><br><br><br>'+
'<div id="comment" style="text-align: justify; text-justify: inter-word;">'+comment+'</div>'+
'</body>'+
'</html>';
var dataUri = 'data:text/html,'+ encodeURIComponent(htmlString);
console.log(dataUri);
//javascript code for multiple file download
function downloadAll(files){
if(files.length == 0) return;
file = files.pop();
var theAnchor = $('<a />')
.attr('href', file[1])
.attr('download',file[0])
.appendTo('body');
theAnchor[0].click();
theAnchor.remove();
downloadAll(files);
}
//dowload start
downloadAll([
[diseaseName+'.jpg', url_base64jp],
[diseaseName+'.doc', dataUri]
]);
console.log("Download Complete");//test
}
}
},
responsive: true,
maintainAspectRatio: false,
data: {
labels: y_axis,
datasets: [
{
data: x_axis,
label: "Random Stuff for Clinic DB",
backgroundColor: "rgba(100,20,40,0.6)",
fill: false
}
]
}
});
}
</script>
</body>
</html>