pdfkit 0.8.3 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +39 -0
- package/README.md +121 -111
- package/js/{font/data → data}/Courier-Bold.afm +0 -0
- package/js/{font/data → data}/Courier-BoldOblique.afm +0 -0
- package/js/{font/data → data}/Courier-Oblique.afm +0 -0
- package/js/{font/data → data}/Courier.afm +0 -0
- package/js/{font/data → data}/Helvetica-Bold.afm +0 -0
- package/js/{font/data → data}/Helvetica-BoldOblique.afm +0 -0
- package/js/{font/data → data}/Helvetica-Oblique.afm +0 -0
- package/js/{font/data → data}/Helvetica.afm +0 -0
- package/js/{font/data → data}/Symbol.afm +0 -0
- package/js/{font/data → data}/Times-Bold.afm +0 -0
- package/js/{font/data → data}/Times-BoldItalic.afm +0 -0
- package/js/{font/data → data}/Times-Italic.afm +0 -0
- package/js/{font/data → data}/Times-Roman.afm +0 -0
- package/js/{font/data → data}/ZapfDingbats.afm +0 -0
- package/js/pdfkit.es5.js +6202 -0
- package/js/pdfkit.es5.js.map +1 -0
- package/js/pdfkit.esnext.js +5549 -0
- package/js/pdfkit.esnext.js.map +1 -0
- package/js/pdfkit.js +5581 -0
- package/js/pdfkit.js.map +1 -0
- package/js/pdfkit.standalone.js +65118 -0
- package/js/virtual-fs.js +70 -0
- package/package.json +52 -22
- package/.npmignore +0 -8
- package/Makefile +0 -30
- package/js/data.js +0 -192
- package/js/document.js +0 -247
- package/js/font/afm.js +0 -170
- package/js/font/data/MustRead.html +0 -19
- package/js/font/embedded.js +0 -234
- package/js/font/standard.js +0 -124
- package/js/font.js +0 -75
- package/js/gradient.js +0 -240
- package/js/image/jpeg.js +0 -78
- package/js/image/png.js +0 -158
- package/js/image.js +0 -53
- package/js/line_wrapper.js +0 -252
- package/js/mixins/annotations.js +0 -133
- package/js/mixins/color.js +0 -298
- package/js/mixins/fonts.js +0 -71
- package/js/mixins/images.js +0 -111
- package/js/mixins/text.js +0 -344
- package/js/mixins/vector.js +0 -302
- package/js/object.js +0 -115
- package/js/page.js +0 -170
- package/js/path.js +0 -366
- package/js/reference.js +0 -109
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
## pdfkit changelog
|
|
2
|
+
|
|
3
|
+
### Unreleased
|
|
4
|
+
|
|
5
|
+
### [v0.11.0] - 2019-12-03
|
|
6
|
+
|
|
7
|
+
- Fix infinite loop when an individual character is bigger than the width of the text.
|
|
8
|
+
- Fix infinite loop when text is positioned after page right margin
|
|
9
|
+
- Allow links in continued text to be stopped by setting link to null
|
|
10
|
+
- Add support to interlaced PNG files
|
|
11
|
+
- Do not emit \_interopDefault helper in commonjs build
|
|
12
|
+
- Fix gradient with multiple stops (#1045)
|
|
13
|
+
- Set link annotation flag to print by default
|
|
14
|
+
- Add support for AcroForms
|
|
15
|
+
- Drop support for (uncommon) cid less fonts on standalone build (reduces bundle size)
|
|
16
|
+
|
|
17
|
+
### [v0.10.0] - 2019-06-06
|
|
18
|
+
|
|
19
|
+
- Fix links to pages within the document
|
|
20
|
+
- Add support for named destinations
|
|
21
|
+
- Throw errors when `dash(...)` is passed invalid lengths
|
|
22
|
+
- Remove PDFDocument#output method
|
|
23
|
+
- Add standalone build (js/pdfkit.standalone.js)
|
|
24
|
+
|
|
25
|
+
### [v0.9.1] - 2019-04-30
|
|
26
|
+
|
|
27
|
+
- Fix setting printing permission
|
|
28
|
+
- Fix corruption of string objects in browser
|
|
29
|
+
- Add option to set default font
|
|
30
|
+
- Remove call to fontkit.openSync
|
|
31
|
+
- Add standalone virtual file system implementation
|
|
32
|
+
- Add option (fontLayoutCache) to disable font layout cache
|
|
33
|
+
|
|
34
|
+
### [v0.9.0] - 2019-1-28
|
|
35
|
+
|
|
36
|
+
- Convert to code base from coffescript to ES6+
|
|
37
|
+
- Fix loading grayscale / transparent PNG files
|
|
38
|
+
- Reduce number of calls to async functions
|
|
39
|
+
- Implement encryption / access control
|
package/README.md
CHANGED
|
@@ -2,164 +2,174 @@
|
|
|
2
2
|
|
|
3
3
|
A JavaScript PDF generation library for Node and the browser.
|
|
4
4
|
|
|
5
|
-
[](https://gratipay.com/devongovett)
|
|
6
|
-
|
|
7
5
|
## Description
|
|
8
6
|
|
|
9
|
-
PDFKit is a PDF document generation library for Node and the browser that makes creating complex, multi-page, printable
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
PDFKit is a PDF document generation library for Node and the browser that makes creating complex, multi-page, printable
|
|
8
|
+
documents easy. The API embraces chainability, and includes both low level functions as well as abstractions for higher
|
|
9
|
+
level functionality. The PDFKit API is designed to be simple, so generating complex documents is often as simple as
|
|
10
|
+
a few function calls.
|
|
13
11
|
|
|
14
12
|
Check out some of the [documentation and examples](http://pdfkit.org/docs/getting_started.html) to see for yourself!
|
|
15
13
|
You can also read the guide as a [self-generated PDF](http://pdfkit.org/docs/guide.pdf) with example output displayed inline.
|
|
16
|
-
If you'd like to see how it was generated, check out the README in the [docs](https://github.com/
|
|
14
|
+
If you'd like to see how it was generated, check out the README in the [docs](https://github.com/foliojs/pdfkit/tree/master/docs)
|
|
17
15
|
folder.
|
|
18
16
|
|
|
19
17
|
You can also try out an interactive in-browser demo of PDFKit [here](http://pdfkit.org/demo/browser.html).
|
|
20
18
|
|
|
21
19
|
## Installation
|
|
22
20
|
|
|
23
|
-
Installation uses the [npm](http://npmjs.org/) package manager.
|
|
21
|
+
Installation uses the [npm](http://npmjs.org/) package manager. Just type the following command after installing npm.
|
|
24
22
|
|
|
25
23
|
npm install pdfkit
|
|
26
24
|
|
|
27
25
|
## Features
|
|
28
26
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
27
|
+
- Vector graphics
|
|
28
|
+
- HTML5 canvas-like API
|
|
29
|
+
- Path operations
|
|
30
|
+
- SVG path parser for easy path creation
|
|
31
|
+
- Transformations
|
|
32
|
+
- Linear and radial gradients
|
|
33
|
+
- Text
|
|
34
|
+
- Line wrapping
|
|
35
|
+
- Text alignments
|
|
36
|
+
- Bulleted lists
|
|
37
|
+
- Font embedding
|
|
38
|
+
- Supports TrueType (.ttf), OpenType (.otf), WOFF, WOFF2, TrueType Collections (.ttc), and Datafork TrueType (.dfont) fonts
|
|
39
|
+
- Font subsetting
|
|
40
|
+
- See [fontkit](http://github.com/foliojs/fontkit) for more details on advanced glyph layout support.
|
|
41
|
+
- Image embedding
|
|
42
|
+
- Supports JPEG and PNG files (including indexed PNGs, and PNGs with transparency)
|
|
43
|
+
- Annotations
|
|
44
|
+
- Links
|
|
45
|
+
- Notes
|
|
46
|
+
- Highlights
|
|
47
|
+
- Underlines
|
|
48
|
+
- etc.
|
|
49
|
+
- AcroForms
|
|
50
|
+
- Outlines
|
|
51
|
+
- PDF security
|
|
52
|
+
- Encryption
|
|
53
|
+
- Access privileges (printing, copying, modifying, annotating, form filling, content accessibility, document assembly)
|
|
54
|
+
|
|
52
55
|
## Coming soon!
|
|
53
56
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
* Even more awesomeness, perhaps written by you! Please fork this repository and send me pull requests.
|
|
60
|
-
|
|
57
|
+
- Patterns fills
|
|
58
|
+
- Higher level APIs for creating tables and laying out content
|
|
59
|
+
- More performance optimizations
|
|
60
|
+
- Even more awesomeness, perhaps written by you! Please fork this repository and send me pull requests.
|
|
61
|
+
|
|
61
62
|
## Example
|
|
62
63
|
|
|
63
|
-
```
|
|
64
|
-
PDFDocument = require
|
|
64
|
+
```javascript
|
|
65
|
+
const PDFDocument = require('pdfkit');
|
|
66
|
+
const fs = require('fs');
|
|
65
67
|
|
|
66
|
-
|
|
67
|
-
doc = new PDFDocument
|
|
68
|
+
// Create a document
|
|
69
|
+
const doc = new PDFDocument();
|
|
68
70
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
doc.pipe
|
|
71
|
+
// Pipe its output somewhere, like to a file or HTTP response
|
|
72
|
+
// See below for browser usage
|
|
73
|
+
doc.pipe(fs.createWriteStream('output.pdf'));
|
|
72
74
|
|
|
73
|
-
|
|
74
|
-
doc
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
// Embed a font, set the font size, and render some text
|
|
76
|
+
doc
|
|
77
|
+
.font('fonts/PalatinoBold.ttf')
|
|
78
|
+
.fontSize(25)
|
|
79
|
+
.text('Some text with an embedded font!', 100, 100);
|
|
77
80
|
|
|
78
|
-
|
|
81
|
+
// Add an image, constrain it to a given size, and center it vertically and horizontally
|
|
79
82
|
doc.image('path/to/image.png', {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
+
fit: [250, 300],
|
|
84
|
+
align: 'center',
|
|
85
|
+
valign: 'center'
|
|
83
86
|
});
|
|
84
87
|
|
|
85
|
-
|
|
86
|
-
doc
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
#
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
88
|
+
// Add another page
|
|
89
|
+
doc
|
|
90
|
+
.addPage()
|
|
91
|
+
.fontSize(25)
|
|
92
|
+
.text('Here is some vector graphics...', 100, 100);
|
|
93
|
+
|
|
94
|
+
// Draw a triangle
|
|
95
|
+
doc
|
|
96
|
+
.save()
|
|
97
|
+
.moveTo(100, 150)
|
|
98
|
+
.lineTo(100, 250)
|
|
99
|
+
.lineTo(200, 250)
|
|
100
|
+
.fill('#FF3300');
|
|
101
|
+
|
|
102
|
+
// Apply some transforms and render an SVG path with the 'even-odd' fill rule
|
|
103
|
+
doc
|
|
104
|
+
.scale(0.6)
|
|
105
|
+
.translate(470, -380)
|
|
106
|
+
.path('M 250,75 L 323,301 131,161 369,161 177,301 z')
|
|
107
|
+
.fill('red', 'even-odd')
|
|
108
|
+
.restore();
|
|
109
|
+
|
|
110
|
+
// Add some text with annotations
|
|
111
|
+
doc
|
|
112
|
+
.addPage()
|
|
113
|
+
.fillColor('blue')
|
|
114
|
+
.text('Here is a link!', 100, 100)
|
|
115
|
+
.underline(100, 100, 160, 27, { color: '#0000FF' })
|
|
116
|
+
.link(100, 100, 160, 27, 'http://google.com/');
|
|
117
|
+
|
|
118
|
+
// Finalize PDF file
|
|
119
|
+
doc.end();
|
|
113
120
|
```
|
|
114
|
-
|
|
115
|
-
[The PDF output from this example](http://pdfkit.org/demo/out.pdf) (with a few additions) shows the power of PDFKit — producing
|
|
116
|
-
complex documents with a very small amount of code.
|
|
121
|
+
|
|
122
|
+
[The PDF output from this example](http://pdfkit.org/demo/out.pdf) (with a few additions) shows the power of PDFKit — producing
|
|
123
|
+
complex documents with a very small amount of code. For more, see the `demo` folder and the
|
|
117
124
|
[PDFKit programming guide](http://pdfkit.org/docs/getting_started.html).
|
|
118
125
|
|
|
119
126
|
## Browser Usage
|
|
120
127
|
|
|
121
|
-
There are
|
|
122
|
-
|
|
123
|
-
|
|
128
|
+
There are three ways to use PDFKit in the browser:
|
|
129
|
+
|
|
130
|
+
- Use [Browserify](http://browserify.org/). See demo [source code](demo/browser.js) and [build script](https://github.com/foliojs/pdfkit/blob/master/package.json#L56)
|
|
131
|
+
- Use [webpack](https://webpack.js.org/). See [complete example](https://github.com/blikblum/pdfkit-webpack-example).
|
|
132
|
+
- Use prebuilt version. Distributed as `pdfkit.standalone.js` file in the [releases](https://github.com/foliojs/pdfkit/releases) or in the package `js` folder.
|
|
124
133
|
|
|
125
|
-
In addition to PDFKit, you'll need somewhere to stream the output to.
|
|
134
|
+
In addition to PDFKit, you'll need somewhere to stream the output to. HTML5 has a
|
|
126
135
|
[Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob) object which can be used to store binary data, and
|
|
127
|
-
get URLs to this data in order to display PDF output inside an iframe, or upload to a server, etc.
|
|
136
|
+
get URLs to this data in order to display PDF output inside an iframe, or upload to a server, etc. In order to
|
|
128
137
|
get a Blob from the output of PDFKit, you can use the [blob-stream](https://github.com/devongovett/blob-stream)
|
|
129
138
|
module.
|
|
130
139
|
|
|
131
|
-
The following example uses Browserify to load `PDFKit` and `blob-stream
|
|
132
|
-
|
|
140
|
+
The following example uses Browserify or webpack to load `PDFKit` and `blob-stream`. See [here](https://codepen.io/blikblum/pen/gJNWMg?editors=1010) and [here](https://codepen.io/blikblum/pen/YboVNq?editors=1010) for examples
|
|
141
|
+
of prebuilt version usage.
|
|
133
142
|
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
PDFDocument = require
|
|
137
|
-
blobStream
|
|
143
|
+
```javascript
|
|
144
|
+
// require dependencies
|
|
145
|
+
const PDFDocument = require('pdfkit');
|
|
146
|
+
const blobStream = require('blob-stream');
|
|
138
147
|
|
|
139
|
-
|
|
140
|
-
doc = new PDFDocument
|
|
148
|
+
// create a document the same way as above
|
|
149
|
+
const doc = new PDFDocument();
|
|
141
150
|
|
|
142
|
-
|
|
143
|
-
stream = doc.pipe(blobStream())
|
|
151
|
+
// pipe the document to a blob
|
|
152
|
+
const stream = doc.pipe(blobStream());
|
|
144
153
|
|
|
145
|
-
|
|
154
|
+
// add your content to the document here, as usual
|
|
146
155
|
|
|
147
|
-
|
|
148
|
-
doc.end()
|
|
149
|
-
stream.on
|
|
150
|
-
|
|
151
|
-
blob = stream.toBlob('application/pdf')
|
|
156
|
+
// get a blob when you're done
|
|
157
|
+
doc.end();
|
|
158
|
+
stream.on('finish', function() {
|
|
159
|
+
// get a blob you can do whatever you like with
|
|
160
|
+
const blob = stream.toBlob('application/pdf');
|
|
152
161
|
|
|
153
|
-
|
|
154
|
-
url = stream.toBlobURL('application/pdf')
|
|
155
|
-
iframe.src = url
|
|
162
|
+
// or get a blob URL for display in the browser
|
|
163
|
+
const url = stream.toBlobURL('application/pdf');
|
|
164
|
+
iframe.src = url;
|
|
165
|
+
});
|
|
156
166
|
```
|
|
157
167
|
|
|
158
168
|
You can see an interactive in-browser demo of PDFKit [here](http://pdfkit.org/demo/browser.html).
|
|
159
169
|
|
|
160
|
-
Note that in order to Browserify a project using PDFKit, you need to install the `brfs` module with npm,
|
|
161
|
-
which is used to load built-in font data into the package. It is listed as a `devDependency` in
|
|
162
|
-
PDFKit's `package.json`, so it isn't installed by default for Node users.
|
|
170
|
+
Note that in order to Browserify a project using PDFKit, you need to install the `brfs` module with npm,
|
|
171
|
+
which is used to load built-in font data into the package. It is listed as a `devDependency` in
|
|
172
|
+
PDFKit's `package.json`, so it isn't installed by default for Node users.
|
|
163
173
|
If you forget to install it, Browserify will print an error message.
|
|
164
174
|
|
|
165
175
|
## Documentation
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|