Skip to content

Commit 83f5f72

Browse files
blikblumdevongovett
authored andcommitted
Convert to EcmaScript (ES6+) (foliojs#859)
1 parent 2567227 commit 83f5f72

File tree

102 files changed

+89231
-3907
lines changed

Some content is hidden

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

102 files changed

+89231
-3907
lines changed

.eslintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "eslint:recommended"
3+
}

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
lib/font/tables/.DS_Store
22
.DS_Store
33
/node_modules/
4-
/tests/
54
node-zlib/
65
src/
76
playground/
87
build/
98
js/
109
demo/bundle.js
1110
*.html
12-
!demo/browser.html
11+
!demo/browser.html
12+
.vscode
13+
coverage

.npmignore

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,11 @@ src/
55
lib/
66
docs/
77
playground/
8-
index.js
8+
.vscode/
9+
coverage/
10+
tests/
11+
index.js
12+
index.html
13+
yarn.lock
14+
rollup.config.js
15+
.eslintrc

Makefile

Lines changed: 0 additions & 30 deletions
This file was deleted.

demo/out.pdf

1.78 KB
Binary file not shown.

demo/test.coffee

Lines changed: 0 additions & 92 deletions
This file was deleted.

demo/test.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
var PDFDocument = require('../');
2+
var tiger = require('./tiger');
3+
var fs = require('fs');
4+
5+
// Create a new PDFDocument
6+
var doc = new PDFDocument;
7+
8+
doc.pipe(fs.createWriteStream('out.pdf'));
9+
10+
// Set some meta data
11+
doc.info['Title'] = 'Test Document';
12+
13+
doc.info['Author'] = 'Devon Govett';
14+
15+
// Register a font name for use later
16+
doc.registerFont('Palatino', 'fonts/PalatinoBold.ttf');
17+
18+
// Set the font, draw some text, and embed an image
19+
doc.font('Palatino').fontSize(25).text('Some text with an embedded font!', 100, 100).fontSize(18).text('PNG and JPEG images:').image('images/test.png', 100, 160, {
20+
width: 412
21+
}).image('images/test.jpeg', 190, 400, {
22+
height: 300
23+
});
24+
25+
// Add another page
26+
doc.addPage().fontSize(25).text('Here is some vector graphics...', 100, 100);
27+
28+
// Draw a triangle and a circle
29+
doc.save().moveTo(100, 150).lineTo(100, 250).lineTo(200, 250).fill("#FF3300");
30+
31+
doc.circle(280, 200, 50).fill("#6600FF");
32+
33+
doc.scale(0.6).translate(470, -380).path('M 250,75 L 323,301 131,161 369,161 177,301 z').fill('red', 'even-odd').restore(); // render an SVG path // fill using the even-odd winding rule
34+
35+
var loremIpsum = '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.';
36+
37+
// Draw some text wrapped to 412 points wide
38+
doc.text('And here is some wrapped text...', 100, 300).font('Helvetica', 13).moveDown().text(loremIpsum, { // move down 1 line
39+
width: 412,
40+
align: 'justify',
41+
indent: 30,
42+
paragraphGap: 5
43+
});
44+
45+
// Add another page, and set the font back
46+
doc.addPage().font('Palatino', 25).text('Rendering some SVG paths...', 100, 100).translate(220, 300);
47+
48+
var i, len, part;
49+
// Render each path that makes up the tiger image
50+
for (i = 0, len = tiger.length; i < len; i++) {
51+
part = tiger[i];
52+
doc.save();
53+
doc.path(part.path); // render an SVG path
54+
if (part['stroke-width']) {
55+
doc.lineWidth(part['stroke-width']);
56+
}
57+
if (part.fill !== 'none' && part.stroke !== 'none') {
58+
doc.fillAndStroke(part.fill, part.stroke);
59+
} else {
60+
if (part.fill !== 'none') {
61+
doc.fill(part.fill);
62+
}
63+
if (part.stroke !== 'none') {
64+
doc.stroke(part.stroke);
65+
}
66+
}
67+
doc.restore();
68+
}
69+
70+
// Add some text with annotations
71+
doc.addPage().fillColor("blue").text('Here is a link!', 100, 100, {
72+
link: 'http://google.com/',
73+
underline: true
74+
});
75+
76+
77+
// Add a list with a font loaded from a TrueType collection file
78+
doc.fillColor('#000').font('fonts/Chalkboard.ttc', 'Chalkboard', 16).list(['One', 'Two', 'Three'], 100, 150);
79+
80+
doc.end();

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ You can also read the guide in PDF form, in this directory or [online](http://pd
55

66
Both the website and the PDF guide are generated from the Literate CoffeeScript (runnable Markdown) files
77
in this directory. The examples are actually run when generating the PDF in order to show the results inline.
8-
The `generate.coffee` file in this directory is actually quite short. It parses the markdown files into a
8+
The `generate.js` file in this directory is actually quite short. It parses the markdown files into a
99
tree structure using [markdown-js](https://github.com/evilstreak/markdown-js), syntax highlights the code
1010
examples using [codemirror](https://github.com/marijnh/codemirror), compiles and runs the code examples and puts the results
1111
inline, and generates the PDF using PDFKit. You can read the generator script source code to get a feeling for

0 commit comments

Comments
 (0)