forked from jussiniinikoski/wasm-pdf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
81 lines (76 loc) · 2.62 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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>WASM-PDF</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.58.3/codemirror.min.css">
<style>
#jsonEditor {
width: 50%;
height: 100vh;
display: inline-block;
overflow-x: scroll; /* Enable horizontal scrolling */
}
#pdfDisplay {
width: 80%;
height: 90vh;
display: inline-block;
overflow-x: scroll; /* Enable horizontal scrolling */
}
.CodeMirror {
height: 100%;
}
#timestamp {
width: 100%;
text-align: center;
}
</style>
</head>
<body>
<div style="display: flex;">
<div id="jsonEditor"></div>
<div style="display:flex; flex-direction: column; width:50%; align-items: center;">
<div id="timestamp"></div>
<iframe id="pdfDisplay"></iframe>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.58.3/codemirror.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.58.3/mode/javascript/javascript.min.js"></script>
<script>
window.addEventListener('DOMContentLoaded', () => {
const editor = CodeMirror(document.getElementById('jsonEditor'), {
lineNumbers: true,
mode: "application/json",
});
fetch("./examples/text-example.json")
.then(response => {
return response.json();
})
.then(doc => {
let date = new Date().toLocaleString();
let title = doc.contents[0].params;
title.text += " (created: " + date + ")";
editor.setValue(JSON.stringify(doc, null, 2));
createPDF(doc);
});
editor.on('change', (cm, change) => {
let start = performance.now();
let doc = JSON.parse(cm.getValue());
createPDF(doc);
});
});
let pdfFileBlobURL = null;
let generatePDF = (data) => {
const blob = new Blob([data], {
type: 'application/pdf'
});
if (pdfFileBlobURL !== null) {
URL.revokeObjectURL(pdfFileBlobURL);
}
pdfFileBlobURL = URL.createObjectURL(blob);
let pdfDisplay = document.getElementById('pdfDisplay');
pdfDisplay.src = pdfFileBlobURL;
}
</script>
</body>
</html>