forked from Hopding/pdf-lib
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest19.html
More file actions
84 lines (70 loc) · 2.42 KB
/
test19.html
File metadata and controls
84 lines (70 loc) · 2.42 KB
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
<!doctype html>
<html lang="en">
<head>
<meta
http-equiv="Content-Security-Policy"
content="
default-src 'self' 'unsafe-inline' blob: resource:;
object-src 'self' data:;
frame-src 'self' data: 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 19</title>
<script type="text/javascript" src="/dist/umd/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/test18.html'">
Prev
</button>
<button onclick="test()">Run Test</button>
<button onclick="window.location.href = '/apps/web/test20.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;
};
async function test() {
const { PDFDocument } = PDFLib;
const [normalPdf, marioImage] = await Promise.all([
fetchBinaryAsset('pdfs/normal.pdf'),
fetchBinaryAsset('images/mario_emblem.png'),
]);
const pdfDoc = await PDFDocument.load(normalPdf);
pdfDoc.setTitle('テスト');
pdfDoc.setAuthor('デンキヤギ');
const page = pdfDoc.insertPage(0);
page.drawText('This is a test page\nwith an image.', {
size: 40,
x: 60,
y: 700,
lineHeight: 50,
});
const image = await pdfDoc.embedPng(marioImage);
page.drawImage(image, { x: 60, y: 500, ...image.scale(1.0) });
const password = 'asdf';
pdfDoc.encrypt({ password });
console.log('PDF encryption with useObjectStreams: false');
console.log('password:', password);
const pdfBytes = await pdfDoc.save({
useObjectStreams: false,
});
renderInIframe(pdfBytes);
}
</script>
</html>