-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
81 lines (76 loc) · 2.5 KB
/
index.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
<html><head><title>Envelope Maker</title>
<script type="text/javascript" src="blob-stream.js"></script>
<script type="text/javascript" src="pdfkit.js"></script>
<script type="text/javascript">
function go() {
var doc = new PDFDocument;
doc.rotate(90);
doc.font('Helvetica').fontSize(11);
doc.text(document.getElementById('from').value, 18, -436);
doc.font('Helvetica').fontSize(14);
var toX = 300;
var toY = -300;
if (document.getElementById('usps').checked) {
toX = 500;
toY = -180;
}
doc.text(document.getElementById('to').value, toX, toY);
stream = doc.pipe(blobStream());
doc.end();
stream.on('finish', function() {
window.open(stream.toBlobURL('application/pdf'));
});
}
function updateLocation() {
var suffix =
'./#from=' + encodeURIComponent(document.getElementById('from').value) +
'&to=' + encodeURIComponent(document.getElementById('to').value) +
'&usps=' + (document.getElementById('usps').checked ? '1' : '0');
document.getElementById('link').href = suffix;
}
function prefill() {
var idx = document.location.href.indexOf('#');
if (idx < 0)
return;
var suffix = document.location.href.substring(idx + 1);
var parts = suffix.split('&');
for (var i = 0; i < parts.length; i++) {
var part = parts[i];
var subidx = part.indexOf('=');
if (subidx < 0)
continue;
var key = part.substr(0, subidx);
var value = part.substr(subidx + 1);
switch (key) {
case 'from':
document.getElementById('from').value = decodeURIComponent(value);
break;
case 'to':
document.getElementById('to').value = decodeURIComponent(value);
break;
case 'usps':
document.getElementById('usps').checked = value == '1';
break;
}
}
}
</script>
</head>
<body onload="javascript:prefill()">
From:<br/>
<textarea id="from" rows="5" cols="40" onkeyup="javascript:updateLocation()" onchange="javascript:updateLocation()">
Alice
123 Four Lane
San Francisco, CA 98765</textarea><br/>
To:<br/>
<textarea id="to" rows="5" cols="40" onkeyup="javascript:updateLocation()" onchange="javascript:updateLocation()">
Bob
456 Tomorrow Drive
New York, NY 01221</textarea><br/>
<input type="checkbox" id="usps" onchange="javascript:updateLocation()">Leave room for USPS delivery confirmation label<br/>
<button onclick="go()">Submit</button><br/>
<a href="./" id="link">Link to this page</a><br/>
<a href="./js/env.html">Try the new version!</a><br/>
<a href="https://github.com/adlr/envelope">Fork me on GitHub</a>
</body>
</html>