forked from vanielf/pdf-lib
-
Notifications
You must be signed in to change notification settings - Fork 29
/
test13.html
139 lines (125 loc) · 5.53 KB
/
test13.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<!doctype html>
<html lang="en">
<head>
<meta
http-equiv="Content-Security-Policy"
content="
default-src 'self' 'unsafe-inline' blob: resource:;
object-src 'self' blob:;
frame-src 'self' blob:;
"
/>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<link rel="stylesheet" type="text/css" href="/apps/web/index.css" />
<title>Test 13</title>
<script type="text/javascript" src="/dist/pdf-lib.js"></script>
<script type="text/javascript" src="/apps/web/utils.js"></script>
</head>
<body>
<div id="button-container">
<button onclick="window.location.href = '/apps/web/test12.html'">
Prev
</button>
<button onclick="test()">Run Test</button>
<button onclick="window.location.href = '/apps/web/test14.html'">
Next
</button>
</div>
<div id="animation-target"></div>
<iframe id="iframe"></iframe>
</body>
<script type="text/javascript">
startFpsTracker('animation-target');
const fetchBinaryAsset = (asset) =>
fetch(`/assets/${asset}`).then((res) => res.arrayBuffer());
const renderInIframe = (pdfBytes) => {
const blob = new Blob([pdfBytes], { type: 'application/pdf' });
const blobUrl = URL.createObjectURL(blob);
document.getElementById('iframe').src = blobUrl;
};
// prettier-ignore
const pngSuite = [
'PngSuite.png', 'basi0g01.png', 'basi0g02.png', 'basi0g04.png',
'basi0g08.png', 'basi0g16.png', 'basi2c08.png', 'basi2c16.png',
'basi3p01.png', 'basi3p02.png', 'basi3p04.png', 'basi3p08.png',
'basi4a08.png', 'basi4a16.png', 'basi6a08.png', 'basi6a16.png',
'basn0g01.png', 'basn0g02.png', 'basn0g04.png', 'basn0g08.png',
'basn0g16.png', 'basn2c08.png', 'basn2c16.png', 'basn3p01.png',
'basn3p02.png', 'basn3p04.png', 'basn3p08.png', 'basn4a08.png',
'basn4a16.png', 'basn6a08.png', 'basn6a16.png', 'bgai4a08.png',
'bgai4a16.png', 'bgan6a08.png', 'bgan6a16.png', 'bgbn4a08.png',
'bggn4a16.png', 'bgwn6a08.png', 'bgyn6a16.png', 'ccwn2c08.png',
'ccwn3p08.png', 'cdfn2c08.png', 'cdhn2c08.png', 'cdsn2c08.png',
'cdun2c08.png', 'ch1n3p04.png', 'ch2n3p08.png', 'cm0n0g04.png',
'cm7n0g04.png', 'cm9n0g04.png', 'cs3n2c16.png', 'cs3n3p08.png',
'cs5n2c08.png', 'cs5n3p08.png', 'cs8n2c08.png', 'cs8n3p08.png',
'ct0n0g04.png', 'ct1n0g04.png', 'cten0g04.png', 'ctfn0g04.png',
'ctgn0g04.png', 'cthn0g04.png', 'ctjn0g04.png', 'ctzn0g04.png',
'exif2c08.png', 'f00n0g08.png', 'f00n2c08.png', 'f01n0g08.png',
'f01n2c08.png', 'f02n0g08.png', 'f02n2c08.png', 'f03n0g08.png',
'f03n2c08.png', 'f04n0g08.png', 'f04n2c08.png', 'f99n0g04.png',
'g03n0g16.png', 'g03n2c08.png', 'g03n3p04.png', 'g04n0g16.png',
'g04n2c08.png', 'g04n3p04.png', 'g05n0g16.png', 'g05n2c08.png',
'g05n3p04.png', 'g07n0g16.png', 'g07n2c08.png', 'g07n3p04.png',
'g10n0g16.png', 'g10n2c08.png', 'g10n3p04.png', 'g25n0g16.png',
'g25n2c08.png', 'g25n3p04.png', 'oi1n0g16.png', 'oi1n2c16.png',
'oi2n0g16.png', 'oi2n2c16.png', 'oi4n0g16.png', 'oi4n2c16.png',
'oi9n0g16.png', 'oi9n2c16.png', 'pp0n2c16.png', 'pp0n6a08.png',
'ps1n0g08.png', 'ps1n2c16.png', 'ps2n0g08.png', 'ps2n2c16.png',
's01i3p01.png', 's01n3p01.png', 's02i3p01.png', 's02n3p01.png',
's03i3p01.png', 's03n3p01.png', 's04i3p01.png', 's04n3p01.png',
's05i3p02.png', 's05n3p02.png', 's06i3p02.png', 's06n3p02.png',
's07i3p02.png', 's07n3p02.png', 's08i3p02.png', 's08n3p02.png',
's09i3p02.png', 's09n3p02.png', 's32i3p04.png', 's32n3p04.png',
's33i3p04.png', 's33n3p04.png', 's34i3p04.png', 's34n3p04.png',
's35i3p04.png', 's35n3p04.png', 's36i3p04.png', 's36n3p04.png',
's37i3p04.png', 's37n3p04.png', 's38i3p04.png', 's38n3p04.png',
's39i3p04.png', 's39n3p04.png', 's40i3p04.png', 's40n3p04.png',
'tbbn0g04.png', 'tbbn2c16.png', 'tbbn3p08.png', 'tbgn2c16.png',
'tbgn3p08.png', 'tbrn2c08.png', 'tbwn0g16.png', 'tbwn3p08.png',
'tbyn3p08.png', 'tm3n3p02.png', 'tp0n0g08.png', 'tp0n2c08.png',
'tp0n3p08.png', 'tp1n3p08.png', 'z00n2c08.png', 'z03n2c08.png',
'z06n2c08.png', 'z09n2c08.png',
];
async function test() {
const { PDFDocument, rgb } = PDFLib;
const pdfDoc = await PDFDocument.create();
const page = pdfDoc.addPage();
const solarizedWhite = rgb(253 / 255, 246 / 255, 227 / 255);
page.drawRectangle({ ...page.getSize(), color: solarizedWhite });
const etweImg = await pdfDoc.embedPng(
await fetchBinaryAsset('images/etwe.png'),
);
page.drawImage(etweImg, {
x: 25,
y: page.getHeight() - 80,
...etweImg.scale(0.2),
});
const selfDriveImg = await pdfDoc.embedPng(
await fetchBinaryAsset('images/self_drive.png'),
);
page.drawImage(selfDriveImg, {
x: page.getWidth() / 2,
y: page.getHeight() - 80,
...selfDriveImg.scale(0.7),
});
const size = 45;
let x = 25;
let y = 5;
for (const path of pngSuite) {
const png = await fetchBinaryAsset(`images/pngsuite/${path}`);
const img = await pdfDoc.embedPng(png);
page.drawImage(img, { x, y, width: size, height: size });
y += size + 5;
if (y + size >= page.getHeight() - 80) {
y = 5;
x += size + 5;
}
}
const pdfBytes = await pdfDoc.save();
renderInIframe(pdfBytes);
}
</script>
</html>