-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathexample.html
More file actions
43 lines (37 loc) · 920 Bytes
/
example.html
File metadata and controls
43 lines (37 loc) · 920 Bytes
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
<!DOCTYPE html>
<html lang=en>
<head>
<meta charset="utf-8" />
<meta name=viewport content="width=device-width, initial-scale=1">
<title>Serverless URL to PDF generator</title>
</head>
<body>
<form id="urlForm">
<input required id=url type=url name=url>
<input type=submit value="Generate PDF">
</form>
<iframe id="viewer">
</iframe>
<script>
document.getElementById("urlForm").addEventListener("submit", function(evt) {
evt.preventDefault();
fetch('YOUR_ENDPOINT_URL/stage/print', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/pdf'
},
body: JSON.stringify({
url: document.getElementById("url").value,
})
}).then(res => res.blob())
.then(data => {
var iframe = document.getElementById('viewer');
iframe.setAttribute('src', URL.createObjectURL(data, {
type: "application/pdf"
}));
}).catch(console.warn)
});
</script>
</body>
</html>