-
Notifications
You must be signed in to change notification settings - Fork 38
/
app.js
32 lines (26 loc) · 778 Bytes
/
app.js
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
import PdfContext from "/src/canvas2pdf";
import blobStream from "blob-stream";
const editor = document.getElementById("editor_source");
const examplePicker = document.getElementById("example_picker");
examplePicker.onchange = function () {
editor.textContent = document.getElementById(examplePicker.value).textContent;
createPdf();
};
const iframe = document.querySelector("iframe");
const createPdf = function () {
const text = editor.textContent;
const stream = blobStream();
const ctx = new PdfContext(stream);
ctx.stream.on("finish", function () {
iframe.src = ctx.stream.toBlobURL("application/pdf");
});
eval(text);
};
document.getElementById("redraw").addEventListener(
"click",
function () {
createPdf();
},
false,
);
createPdf();