pdfkit 0.17.2 → 0.18.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/.yarn/install-state.gz +0 -0
- package/.yarn/releases/yarn-4.10.3.cjs +942 -0
- package/.yarnrc.yml +3 -0
- package/CHANGELOG.md +150 -134
- package/LICENSE +7 -7
- package/README.md +189 -182
- package/js/data/Courier-Bold.afm +342 -342
- package/js/data/Courier-BoldOblique.afm +342 -342
- package/js/data/Courier-Oblique.afm +342 -342
- package/js/data/Courier.afm +342 -342
- package/js/data/Helvetica-Bold.afm +2827 -2827
- package/js/data/Helvetica-BoldOblique.afm +2827 -2827
- package/js/data/Helvetica-Oblique.afm +3051 -3051
- package/js/data/Helvetica.afm +3051 -3051
- package/js/data/Symbol.afm +213 -213
- package/js/data/Times-Bold.afm +2588 -2588
- package/js/data/Times-BoldItalic.afm +2384 -2384
- package/js/data/Times-Italic.afm +2667 -2667
- package/js/data/Times-Roman.afm +2419 -2419
- package/js/data/ZapfDingbats.afm +225 -225
- package/js/pdfkit.es.js +424 -159
- package/js/pdfkit.es.js.map +1 -1
- package/js/pdfkit.js +423 -159
- package/js/pdfkit.js.map +1 -1
- package/js/pdfkit.standalone.js +27350 -31546
- package/jsconfig.json +12 -12
- package/package.json +93 -92
- package/types/jest.custom-matchers.d.ts +28 -28
- package/js/pdfkit.es5.js +0 -7493
- package/js/pdfkit.es5.js.map +0 -1
- package/js/pdfkit.esnext.js +0 -6782
- package/js/pdfkit.esnext.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,182 +1,189 @@
|
|
|
1
|
-
# PDFKit
|
|
2
|
-
|
|
3
|
-
A JavaScript PDF generation library for Node and the browser.
|
|
4
|
-
|
|
5
|
-
## Description
|
|
6
|
-
|
|
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.
|
|
11
|
-
|
|
12
|
-
Check out some of the [documentation and examples](http://pdfkit.org/docs/getting_started.html) to see for yourself!
|
|
13
|
-
You can also read the guide as a [self-generated PDF](http://pdfkit.org/docs/guide.pdf) with example output displayed inline.
|
|
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)
|
|
15
|
-
folder.
|
|
16
|
-
|
|
17
|
-
You can also try out an interactive in-browser demo of PDFKit [here](http://pdfkit.org/demo/browser.html).
|
|
18
|
-
|
|
19
|
-
## Installation
|
|
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
|
-
doc
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
// Add
|
|
90
|
-
doc
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
.
|
|
99
|
-
.
|
|
100
|
-
.
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
.
|
|
106
|
-
.
|
|
107
|
-
.
|
|
108
|
-
.fill('
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
.
|
|
114
|
-
.
|
|
115
|
-
.
|
|
116
|
-
.
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
//
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
1
|
+
# PDFKit
|
|
2
|
+
|
|
3
|
+
A JavaScript PDF generation library for Node and the browser.
|
|
4
|
+
|
|
5
|
+
## Description
|
|
6
|
+
|
|
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.
|
|
11
|
+
|
|
12
|
+
Check out some of the [documentation and examples](http://pdfkit.org/docs/getting_started.html) to see for yourself!
|
|
13
|
+
You can also read the guide as a [self-generated PDF](http://pdfkit.org/docs/guide.pdf) with example output displayed inline.
|
|
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)
|
|
15
|
+
folder.
|
|
16
|
+
|
|
17
|
+
You can also try out an interactive in-browser demo of PDFKit [here](http://pdfkit.org/demo/browser.html).
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
Use [npm](http://npmjs.org/) or [yarn](https://yarnpkg.com/) package manager. Just type the following command:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
# with npm
|
|
25
|
+
npm install pdfkit
|
|
26
|
+
|
|
27
|
+
# with yarn
|
|
28
|
+
yarn add pdfkit
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Features
|
|
32
|
+
|
|
33
|
+
- Vector graphics
|
|
34
|
+
- HTML5 canvas-like API
|
|
35
|
+
- Path operations
|
|
36
|
+
- SVG path parser for easy path creation
|
|
37
|
+
- Transformations
|
|
38
|
+
- Linear and radial gradients
|
|
39
|
+
- Text
|
|
40
|
+
- Line wrapping (with soft hyphen recognition)
|
|
41
|
+
- Text alignments
|
|
42
|
+
- Bulleted lists
|
|
43
|
+
- Font embedding
|
|
44
|
+
- Supports TrueType (.ttf), OpenType (.otf), WOFF, WOFF2, TrueType Collections (.ttc), and Datafork TrueType (.dfont) fonts
|
|
45
|
+
- Font subsetting
|
|
46
|
+
- See [fontkit](http://github.com/foliojs/fontkit) for more details on advanced glyph layout support.
|
|
47
|
+
- Image embedding
|
|
48
|
+
- Supports JPEG and PNG files (including indexed PNGs, and PNGs with transparency)
|
|
49
|
+
- Tables
|
|
50
|
+
- Annotations
|
|
51
|
+
- Links
|
|
52
|
+
- Notes
|
|
53
|
+
- Highlights
|
|
54
|
+
- Underlines
|
|
55
|
+
- etc.
|
|
56
|
+
- AcroForms
|
|
57
|
+
- Outlines
|
|
58
|
+
- PDF security
|
|
59
|
+
- Encryption
|
|
60
|
+
- Access privileges (printing, copying, modifying, annotating, form filling, content accessibility, document assembly)
|
|
61
|
+
- Accessibility support (marked content, logical structure, Tagged PDF, PDF/UA)
|
|
62
|
+
|
|
63
|
+
## Coming soon!
|
|
64
|
+
|
|
65
|
+
- Patterns fills
|
|
66
|
+
- Higher level APIs for laying out content
|
|
67
|
+
- More performance optimizations
|
|
68
|
+
- Even more awesomeness, perhaps written by you! Please fork this repository and send me pull requests.
|
|
69
|
+
|
|
70
|
+
## Example
|
|
71
|
+
|
|
72
|
+
```javascript
|
|
73
|
+
const PDFDocument = require('pdfkit');
|
|
74
|
+
const fs = require('fs');
|
|
75
|
+
|
|
76
|
+
// Create a document
|
|
77
|
+
const doc = new PDFDocument();
|
|
78
|
+
|
|
79
|
+
// Pipe its output somewhere, like to a file or HTTP response
|
|
80
|
+
// See below for browser usage
|
|
81
|
+
doc.pipe(fs.createWriteStream('output.pdf'));
|
|
82
|
+
|
|
83
|
+
// Embed a font, set the font size, and render some text
|
|
84
|
+
doc
|
|
85
|
+
.font('fonts/PalatinoBold.ttf')
|
|
86
|
+
.fontSize(25)
|
|
87
|
+
.text('Some text with an embedded font!', 100, 100);
|
|
88
|
+
|
|
89
|
+
// Add an image, constrain it to a given size, and center it vertically and horizontally
|
|
90
|
+
doc.image('path/to/image.png', {
|
|
91
|
+
fit: [250, 300],
|
|
92
|
+
align: 'center',
|
|
93
|
+
valign: 'center'
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// Add another page
|
|
97
|
+
doc
|
|
98
|
+
.addPage()
|
|
99
|
+
.fontSize(25)
|
|
100
|
+
.text('Here is some vector graphics...', 100, 100);
|
|
101
|
+
|
|
102
|
+
// Draw a triangle
|
|
103
|
+
doc
|
|
104
|
+
.save()
|
|
105
|
+
.moveTo(100, 150)
|
|
106
|
+
.lineTo(100, 250)
|
|
107
|
+
.lineTo(200, 250)
|
|
108
|
+
.fill('#FF3300');
|
|
109
|
+
|
|
110
|
+
// Apply some transforms and render an SVG path with the 'even-odd' fill rule
|
|
111
|
+
doc
|
|
112
|
+
.scale(0.6)
|
|
113
|
+
.translate(470, -380)
|
|
114
|
+
.path('M 250,75 L 323,301 131,161 369,161 177,301 z')
|
|
115
|
+
.fill('red', 'even-odd')
|
|
116
|
+
.restore();
|
|
117
|
+
|
|
118
|
+
// Add some text with annotations
|
|
119
|
+
doc
|
|
120
|
+
.addPage()
|
|
121
|
+
.fillColor('blue')
|
|
122
|
+
.text('Here is a link!', 100, 100)
|
|
123
|
+
.underline(100, 100, 160, 27, { color: '#0000FF' })
|
|
124
|
+
.link(100, 100, 160, 27, 'http://google.com/');
|
|
125
|
+
|
|
126
|
+
// Finalize PDF file
|
|
127
|
+
doc.end();
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
[The PDF output from this example](http://pdfkit.org/demo/out.pdf) (with a few additions) shows the power of PDFKit — producing
|
|
131
|
+
complex documents with a very small amount of code. For more, see the `demo` folder and the
|
|
132
|
+
[PDFKit programming guide](http://pdfkit.org/docs/getting_started.html).
|
|
133
|
+
|
|
134
|
+
## Browser Usage
|
|
135
|
+
|
|
136
|
+
There are three ways to use PDFKit in the browser:
|
|
137
|
+
|
|
138
|
+
- Use [Browserify](http://browserify.org/). See demo [source code](https://github.com/foliojs/pdfkit/blob/master/examples/browserify/browser.js) and [build script](https://github.com/foliojs/pdfkit/blob/master/package.json#L62)
|
|
139
|
+
- Use [webpack](https://webpack.js.org/). See [complete example](https://github.com/foliojs/pdfkit/blob/master/examples/webpack).
|
|
140
|
+
- Use prebuilt version. Distributed as `pdfkit.standalone.js` file in the [releases](https://github.com/foliojs/pdfkit/releases) or in the package `js` folder.
|
|
141
|
+
|
|
142
|
+
In addition to PDFKit, you'll need somewhere to stream the output to. HTML5 has a
|
|
143
|
+
[Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob) object which can be used to store binary data, and
|
|
144
|
+
get URLs to this data in order to display PDF output inside an iframe, or upload to a server, etc. In order to
|
|
145
|
+
get a Blob from the output of PDFKit, you can use the [blob-stream](https://github.com/devongovett/blob-stream)
|
|
146
|
+
module.
|
|
147
|
+
|
|
148
|
+
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
|
|
149
|
+
of prebuilt version usage.
|
|
150
|
+
|
|
151
|
+
```javascript
|
|
152
|
+
// require dependencies
|
|
153
|
+
const PDFDocument = require('pdfkit');
|
|
154
|
+
const blobStream = require('blob-stream');
|
|
155
|
+
|
|
156
|
+
// create a document the same way as above
|
|
157
|
+
const doc = new PDFDocument();
|
|
158
|
+
|
|
159
|
+
// pipe the document to a blob
|
|
160
|
+
const stream = doc.pipe(blobStream());
|
|
161
|
+
|
|
162
|
+
// add your content to the document here, as usual
|
|
163
|
+
|
|
164
|
+
// get a blob when you are done
|
|
165
|
+
doc.end();
|
|
166
|
+
stream.on('finish', function() {
|
|
167
|
+
// get a blob you can do whatever you like with
|
|
168
|
+
const blob = stream.toBlob('application/pdf');
|
|
169
|
+
|
|
170
|
+
// or get a blob URL for display in the browser
|
|
171
|
+
const url = stream.toBlobURL('application/pdf');
|
|
172
|
+
iframe.src = url;
|
|
173
|
+
});
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
You can see an interactive in-browser demo of PDFKit [here](http://pdfkit.org/demo/browser.html).
|
|
177
|
+
|
|
178
|
+
Note that in order to Browserify a project using PDFKit, you need to install the `brfs` module,
|
|
179
|
+
which is used to load built-in font data into the package. It is listed as a `devDependency` in
|
|
180
|
+
PDFKit's `package.json`, so it isn't installed by default for Node users.
|
|
181
|
+
If you forget to install it, Browserify will print an error message.
|
|
182
|
+
|
|
183
|
+
## Documentation
|
|
184
|
+
|
|
185
|
+
For complete API documentation and more examples, see the [PDFKit website](http://pdfkit.org/).
|
|
186
|
+
|
|
187
|
+
## License
|
|
188
|
+
|
|
189
|
+
PDFKit is available under the MIT license.
|