This repository has been archived by the owner on Jun 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 52
/
example2.html
51 lines (46 loc) · 1.49 KB
/
example2.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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>WASM-PDF</title>
</head>
<body>
<p>
<span id="message">One moment, creating PDF...</span>
<a href="javascript:void(0)" download="lorem-ipsum.pdf" style="display: none" id="download-link">Download PDF</a>
</p>
<script>
window.addEventListener('DOMContentLoaded', () => {
fetch("./examples/text-example.json")
.then(response => {
return response.json();
})
.then(doc => {
// Change the title to show date (now)
let date = new Date().toLocaleString();
let title = doc.contents[0].params;
title.text += " (created: " + date + ")";
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 downloadLink = document.getElementById("download-link");
downloadLink.href = pdfFileBlobURL;
downloadLink.style.display = 'block';
let message = document.getElementById("message");
message.style.display = 'none';
}
let jsonOut = (data) => {
console.log(JSON.stringify(data));
};
</script>
<script type="text/javascript" src="index.js"></script></body>
</html>