Skip to content

Commit 0bf09fb

Browse files
committed
update browserify
1 parent 52daaf6 commit 0bf09fb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+3049
-56
lines changed

examples - kopie/attachment.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const PDFDocument = require('../');
2+
const fs = require('fs');
3+
const path = require('path');
4+
5+
const doc = new PDFDocument({ pdfVersion: '1.4' });
6+
7+
doc.pipe(fs.createWriteStream('attachment.pdf'));
8+
9+
doc.info['Title'] = 'Attachment Test';
10+
11+
// add an embedded file from file system
12+
doc.file(path.join(__dirname, 'images', 'test.png'), {
13+
name: 'test.png',
14+
type: 'image/png',
15+
description: 'this is a test image'
16+
});
17+
18+
// add some text
19+
doc.text(`This PDF contains three text files:
20+
Two file attachment annotations and one embedded file.
21+
If you can see them (not every PDF viewer supports embedded files),
22+
hover over the paperclip to see its description!`);
23+
24+
// add a file attachment annotation
25+
// first, declare the file to be attached
26+
const file = {
27+
src: Buffer.from('buffered input!'),
28+
name: 'embedded.txt',
29+
creationDate: new Date(2020, 3, 1)
30+
};
31+
// then, add the annotation
32+
doc.fileAnnotation(100, 150, 10, doc.currentLineHeight(), file);
33+
34+
// declared files can be reused, but they will show up separately in the PDF Viewer's attachments panel
35+
// we're going to use the paperclip icon for this one together with a short description
36+
// be aware that some PDF Viewers may not render the icon correctly — or not at all
37+
doc.fileAnnotation(150, 150, 10, doc.currentLineHeight(), file, {
38+
Name: 'Paperclip',
39+
Contents: 'Paperclip attachment'
40+
});
41+
42+
doc.end();

examples - kopie/attachment.pdf

343 KB
Binary file not shown.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<!doctype html>
2+
<html>
3+
4+
<head>
5+
<meta charset="utf-8">
6+
<style>
7+
body {
8+
width: 1230px;
9+
margin: 20px auto;
10+
font-family: Georgia;
11+
}
12+
13+
h1 {
14+
margin: 0;
15+
}
16+
17+
18+
a {
19+
color: blue;
20+
}
21+
22+
#editor {
23+
width: 600px;
24+
height: 775px;
25+
margin-right: 20px;
26+
display: inline-block;
27+
}
28+
29+
iframe {
30+
border: 1px solid black;
31+
}
32+
</style>
33+
</head>
34+
35+
<body>
36+
<h1>PDFKit Browser Demo</h1>
37+
<p>Bundled with Browserify</p>
38+
<p><a href="http://pdfkit.org/">Website</a> | <a href="http://github.com/foliojs/pdfkit">Github</a></p>
39+
<div id="editor"></div>
40+
<iframe width="600" height="775"></iframe>
41+
<script src="bundle.js"></script>
42+
<script>
43+
(function (i, s, o, g, r, a, m) {
44+
i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () {
45+
(i[r].q = i[r].q || []).push(arguments)
46+
}, i[r].l = 1 * new Date(); a = s.createElement(o),
47+
m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m)
48+
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
49+
ga('create', 'UA-48340245-1', 'pdfkit.org');
50+
ga('send', 'pageview');
51+
</script>
52+
</body>
53+
54+
</html>
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
var PDFDocument = require('../..');
2+
var blobStream = require('blob-stream');
3+
var ace = require('brace');
4+
require('brace/mode/javascript');
5+
require('brace/theme/monokai');
6+
7+
var lorem =
8+
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam in suscipit purus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Vivamus nec hendrerit felis. Morbi aliquam facilisis risus eu lacinia. Sed eu leo in turpis fringilla hendrerit. Ut nec accumsan nisl. Suspendisse rhoncus nisl posuere tortor tempus et dapibus elit porta. Cras leo neque, elementum a rhoncus ut, vestibulum non nibh. Phasellus pretium justo turpis. Etiam vulputate, odio vitae tincidunt ultricies, eros odio dapibus nisi, ut tincidunt lacus arcu eu elit. Aenean velit erat, vehicula eget lacinia ut, dignissim non tellus. Aliquam nec lacus mi, sed vestibulum nunc. Suspendisse potenti. Curabitur vitae sem turpis. Vestibulum sed neque eget dolor dapibus porttitor at sit amet sem. Fusce a turpis lorem. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae;\nMauris at ante tellus. Vestibulum a metus lectus. Praesent tempor purus a lacus blandit eget gravida ante hendrerit. Cras et eros metus. Sed commodo malesuada eros, vitae interdum augue semper quis. Fusce id magna nunc. Curabitur sollicitudin placerat semper. Cras et mi neque, a dignissim risus. Nulla venenatis porta lacus, vel rhoncus lectus tempor vitae. Duis sagittis venenatis rutrum. Curabitur tempor massa tortor.';
9+
10+
function makePDF(PDFDocument, blobStream, lorem, iframe) {
11+
// create a document and pipe to a blob
12+
var doc = new PDFDocument();
13+
var stream = doc.pipe(blobStream());
14+
15+
// draw some text
16+
doc.fontSize(25).text('Here is some vector graphics...', 100, 80);
17+
18+
// some vector graphics
19+
doc
20+
.save()
21+
.moveTo(100, 150)
22+
.lineTo(100, 250)
23+
.lineTo(200, 250)
24+
.fill('#FF3300');
25+
26+
doc.circle(280, 200, 50).fill('#6600FF');
27+
28+
// an SVG path
29+
doc
30+
.scale(0.6)
31+
.translate(470, 130)
32+
.path('M 250,75 L 323,301 131,161 369,161 177,301 z')
33+
.fill('red', 'even-odd')
34+
.restore();
35+
36+
doc.save();
37+
// a gradient fill
38+
var gradient = doc
39+
.linearGradient(100, 300, 200, 300)
40+
.stop(0, 'green')
41+
.stop(0.5, 'red')
42+
.stop(1, 'green');
43+
doc.rect(100, 300, 100, 100).fill(gradient);
44+
45+
// stroke & fill uncolored tiling pattern
46+
47+
var stripe45d = doc.pattern(
48+
[1, 1, 4, 4],
49+
3,
50+
3,
51+
'1 w 0 1 m 4 5 l s 2 0 m 5 3 l s'
52+
);
53+
doc.circle(280, 350, 50).fill([stripe45d, 'blue']);
54+
55+
doc
56+
.rect(380, 300, 100, 100)
57+
.fillColor('lime')
58+
.strokeColor([stripe45d, 'orange'])
59+
.lineWidth(5)
60+
.fillAndStroke();
61+
doc.restore();
62+
63+
// and some justified text wrapped into columns
64+
doc
65+
.text('And here is some wrapped text...', 100, 450)
66+
.font('Times-Roman', 13)
67+
.moveDown()
68+
.text(lorem, {
69+
width: 412,
70+
align: 'justify',
71+
indent: 30,
72+
columns: 2,
73+
height: 300,
74+
ellipsis: true
75+
});
76+
77+
// end and display the document in the iframe to the right
78+
doc.end();
79+
stream.on('finish', function() {
80+
iframe.src = stream.toBlobURL('application/pdf');
81+
});
82+
}
83+
84+
var editor = ace.edit('editor');
85+
editor.setTheme('ace/theme/monokai');
86+
editor.getSession().setMode('ace/mode/javascript');
87+
editor.setValue(
88+
makePDF
89+
.toString()
90+
.split('\n')
91+
.slice(1, -1)
92+
.join('\n')
93+
.replace(/^ /gm, '')
94+
);
95+
editor
96+
.getSession()
97+
.getSelection()
98+
.clearSelection();
99+
100+
var iframe = document.querySelector('iframe');
101+
makePDF(PDFDocument, blobStream, lorem, iframe);
102+
103+
let debounceTimeout;
104+
105+
editor.getSession().on('change', function() {
106+
try {
107+
if (debounceTimeout) {
108+
clearTimeout(debounceTimeout);
109+
}
110+
var fn = new Function(
111+
'PDFDocument',
112+
'blobStream',
113+
'lorem',
114+
'iframe',
115+
editor.getValue()
116+
);
117+
debounceTimeout = setTimeout(() => {
118+
fn(PDFDocument, blobStream, lorem, iframe);
119+
debounceTimeout = undefined;
120+
}, 100);
121+
} catch (e) {
122+
console.log(e);
123+
}
124+
});
180 KB
Binary file not shown.
703 KB
Binary file not shown.

examples - kopie/fonts/GoodDog.ttf

30.1 KB
Binary file not shown.
2.3 MB
Binary file not shown.
230 KB
Binary file not shown.
164 KB
Binary file not shown.

0 commit comments

Comments
 (0)