-
Notifications
You must be signed in to change notification settings - Fork 10
/
oldindex.html
63 lines (55 loc) · 2 KB
/
oldindex.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
<html>
<head>
<meta charset="utf-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/BrowserFS/2.0.0/browserfs.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/downloadjs/1.4.8/download.min.js"></script>
<script>
if (!WebAssembly.instantiateStreaming) { // polyfill
WebAssembly.instantiateStreaming = async (resp, importObject) => {
const source = await (await resp).arrayBuffer()
return await WebAssembly.instantiate(source, importObject)
}
}
// Configures BrowserFS to use the InMemory file system.
BrowserFS.configure({
fs: "InMemory"
}, function(e) {
if (e) {
// An error happened!
throw e;
}
var s = document.createElement('script');
s.src = "wasm_exec.js";
document.head.appendChild(s);
// Otherwise, BrowserFS is ready-to-use!
var fs = BrowserFS.BFSRequire('fs');
var Buffer = BrowserFS.BFSRequire('buffer').Buffer;
// Write the test pdf file to the InMemory FS
fetch('/PDFReference.pdf').then(function(res) { return res.arrayBuffer() }).then(function(buffer) {
fs.writeFile('/test.pdf', Buffer.from(buffer), function(err) {
// check it is there
fs.readFile('/test.pdf', function(err, contents) {
console.log(contents);
done();
});
});
});
function done() {
const go = new Go();
WebAssembly.instantiateStreaming(fetch("pdfcpu.wasm"), go.importObject).then((result) => {
go.argv = ['pdfcpu.wasm', 'trim', '-pages', '1', '/test.pdf', '/first_page.pdf'];
var st = Date.now();
go.run(result.instance);
console.log('Time taken:', Date.now() - st);
fs.readFile('/first_page.pdf', function(err, contents) {
console.log("after run main:", err, contents);
// debugger;
// download(new Blob([contents]), 'first_page.pdf');
});
});
}
});
</script>
</head>
<body>See console for log</body>
</html>