pdfkit 0.8.2 → 0.10.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.
Files changed (50) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/LICENSE +7 -7
  3. package/README.md +175 -171
  4. package/js/{font/data → data}/Courier-Bold.afm +342 -342
  5. package/js/{font/data → data}/Courier-BoldOblique.afm +342 -342
  6. package/js/{font/data → data}/Courier-Oblique.afm +342 -342
  7. package/js/{font/data → data}/Courier.afm +342 -342
  8. package/js/{font/data → data}/Helvetica-Bold.afm +2827 -2827
  9. package/js/{font/data → data}/Helvetica-BoldOblique.afm +2827 -2827
  10. package/js/{font/data → data}/Helvetica-Oblique.afm +3051 -3051
  11. package/js/{font/data → data}/Helvetica.afm +3051 -3051
  12. package/js/{font/data → data}/Symbol.afm +213 -213
  13. package/js/{font/data → data}/Times-Bold.afm +2588 -2588
  14. package/js/{font/data → data}/Times-BoldItalic.afm +2384 -2384
  15. package/js/{font/data → data}/Times-Italic.afm +2667 -2667
  16. package/js/{font/data → data}/Times-Roman.afm +2419 -2419
  17. package/js/{font/data → data}/ZapfDingbats.afm +225 -225
  18. package/js/pdfkit.es5.js +5724 -0
  19. package/js/pdfkit.es5.js.map +1 -0
  20. package/js/pdfkit.esnext.js +5144 -0
  21. package/js/pdfkit.esnext.js.map +1 -0
  22. package/js/pdfkit.js +5112 -0
  23. package/js/pdfkit.js.map +1 -0
  24. package/js/pdfkit.standalone.js +68105 -0
  25. package/js/virtual-fs.js +70 -0
  26. package/package.json +85 -55
  27. package/.npmignore +0 -8
  28. package/Makefile +0 -30
  29. package/js/data.js +0 -192
  30. package/js/document.js +0 -247
  31. package/js/font/afm.js +0 -170
  32. package/js/font/data/MustRead.html +0 -19
  33. package/js/font/embedded.js +0 -234
  34. package/js/font/standard.js +0 -124
  35. package/js/font.js +0 -75
  36. package/js/gradient.js +0 -240
  37. package/js/image/jpeg.js +0 -78
  38. package/js/image/png.js +0 -158
  39. package/js/image.js +0 -53
  40. package/js/line_wrapper.js +0 -252
  41. package/js/mixins/annotations.js +0 -133
  42. package/js/mixins/color.js +0 -304
  43. package/js/mixins/fonts.js +0 -69
  44. package/js/mixins/images.js +0 -111
  45. package/js/mixins/text.js +0 -337
  46. package/js/mixins/vector.js +0 -265
  47. package/js/object.js +0 -114
  48. package/js/page.js +0 -170
  49. package/js/path.js +0 -366
  50. package/js/reference.js +0 -109
package/CHANGELOG.md ADDED
@@ -0,0 +1,27 @@
1
+ ## pdfkit changelog
2
+
3
+ ### Unreleased
4
+
5
+ ### [v0.10.0] - 2019-06-06
6
+
7
+ - Fix links to pages within the document
8
+ - Add support for named destinations
9
+ - Throw errors when `dash(...)` is passed invalid lengths
10
+ - Remove PDFDocument#output method
11
+ - Add standalone build (js/pdfkit.standalone.js)
12
+
13
+ ### [v0.9.1] - 2019-04-30
14
+
15
+ - Fix setting printing permission
16
+ - Fix corruption of string objects in browser
17
+ - Add option to set default font
18
+ - Remove call to fontkit.openSync
19
+ - Add standalone virtual file system implementation
20
+ - Add option (fontLayoutCache) to disable font layout cache
21
+
22
+ ### [v0.9.0] - 2019-1-28
23
+
24
+ - Convert to code base from coffescript to ES6+
25
+ - Fix loading grayscale / transparent PNG files
26
+ - Reduce number of calls to async functions
27
+ - Implement encryption / access control
package/LICENSE CHANGED
@@ -1,8 +1,8 @@
1
- MIT LICENSE
2
- Copyright (c) 2014 Devon Govett
3
-
4
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
-
6
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
-
1
+ MIT LICENSE
2
+ Copyright (c) 2014 Devon Govett
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
8
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,171 +1,175 @@
1
- # PDFKit
2
-
3
- A JavaScript PDF generation library for Node and the browser.
4
-
5
- [![](https://img.shields.io/gratipay/devongovett.svg)](https://gratipay.com/devongovett)
6
-
7
- ## Description
8
-
9
- PDFKit is a PDF document generation library for Node and the browser that makes creating complex, multi-page, printable documents easy.
10
- It's written in CoffeeScript, but you can choose to use the API in plain 'ol JavaScript if you like. The API embraces
11
- chainability, and includes both low level functions as well as abstractions for higher level functionality. The PDFKit API
12
- is designed to be simple, so generating complex documents is often as simple as a few function calls.
13
-
14
- Check out some of the [documentation and examples](http://pdfkit.org/docs/getting_started.html) to see for yourself!
15
- 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/devongovett/pdfkit/tree/master/docs)
17
- folder.
18
-
19
- You can also try out an interactive in-browser demo of PDFKit [here](http://pdfkit.org/demo/browser.html).
20
-
21
- ## Installation
22
-
23
- Installation uses the [npm](http://npmjs.org/) package manager. Just type the following command after installing npm.
24
-
25
- npm install pdfkit
26
-
27
- ## Features
28
-
29
- * Vector graphics
30
- * HTML5 canvas-like API
31
- * Path operations
32
- * SVG path parser for easy path creation
33
- * Transformations
34
- * Linear and radial gradients
35
- * Text
36
- * Line wrapping
37
- * Text alignments
38
- * Bulleted lists
39
- * Font embedding
40
- * Supports TrueType (.ttf), OpenType (.otf), WOFF, WOFF2, TrueType Collections (.ttc), and Datafork TrueType (.dfont) fonts
41
- * Font subsetting
42
- * See [fontkit](http://github.com/devongovett/fontkit) for more details on advanced glyph layout support.
43
- * Image embedding
44
- * Supports JPEG and PNG files (including indexed PNGs, and PNGs with transparency)
45
- * Annotations
46
- * Links
47
- * Notes
48
- * Highlights
49
- * Underlines
50
- * etc.
51
-
52
- ## Coming soon!
53
-
54
- * Patterns fills
55
- * Outlines
56
- * PDF Security
57
- * Higher level APIs for creating tables and laying out content
58
- * More performance optimizations
59
- * Even more awesomeness, perhaps written by you! Please fork this repository and send me pull requests.
60
-
61
- ## Example
62
-
63
- ```coffeescript
64
- PDFDocument = require 'pdfkit'
65
-
66
- # Create a document
67
- doc = new PDFDocument
68
-
69
- # Pipe its output somewhere, like to a file or HTTP response
70
- # See below for browser usage
71
- doc.pipe fs.createWriteStream('output.pdf')
72
-
73
- # Embed a font, set the font size, and render some text
74
- doc.font('fonts/PalatinoBold.ttf')
75
- .fontSize(25)
76
- .text('Some text with an embedded font!', 100, 100)
77
-
78
- # Add an image, constrain it to a given size, and center it vertically and horizontally
79
- doc.image('path/to/image.png', {
80
- fit: [250, 300],
81
- align: 'center',
82
- valign: 'center'
83
- });
84
-
85
- # Add another page
86
- doc.addPage()
87
- .fontSize(25)
88
- .text('Here is some vector graphics...', 100, 100)
89
-
90
- # Draw a triangle
91
- doc.save()
92
- .moveTo(100, 150)
93
- .lineTo(100, 250)
94
- .lineTo(200, 250)
95
- .fill("#FF3300")
96
-
97
- # Apply some transforms and render an SVG path with the 'even-odd' fill rule
98
- doc.scale(0.6)
99
- .translate(470, -380)
100
- .path('M 250,75 L 323,301 131,161 369,161 177,301 z')
101
- .fill('red', 'even-odd')
102
- .restore()
103
-
104
- # Add some text with annotations
105
- doc.addPage()
106
- .fillColor("blue")
107
- .text('Here is a link!', 100, 100)
108
- .underline(100, 100, 160, 27, color: "#0000FF")
109
- .link(100, 100, 160, 27, 'http://google.com/')
110
-
111
- # Finalize PDF file
112
- doc.end()
113
- ```
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. For more, see the `demo` folder and the
117
- [PDFKit programming guide](http://pdfkit.org/docs/getting_started.html).
118
-
119
- ## Browser Usage
120
-
121
- There are two ways to use PDFKit in the browser. The first is to use [Browserify](http://browserify.org/),
122
- which is a Node module packager for the browser with the familiar `require` syntax. The second is to use
123
- a prebuilt version of PDFKit, which you can [download from Github](https://github.com/devongovett/pdfkit/releases).
124
-
125
- In addition to PDFKit, you'll need somewhere to stream the output to. HTML5 has a
126
- [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. In order to
128
- get a Blob from the output of PDFKit, you can use the [blob-stream](https://github.com/devongovett/blob-stream)
129
- module.
130
-
131
- The following example uses Browserify to load `PDFKit` and `blob-stream`, but if you're not using Browserify,
132
- you can load them in whatever way you'd like (e.g. script tags).
133
-
134
- ```coffeescript
135
- # require dependencies
136
- PDFDocument = require 'pdfkit'
137
- blobStream = require 'blob-stream'
138
-
139
- # create a document the same way as above
140
- doc = new PDFDocument
141
-
142
- # pipe the document to a blob
143
- stream = doc.pipe(blobStream())
144
-
145
- # add your content to the document here, as usual
146
-
147
- # get a blob when you're done
148
- doc.end()
149
- stream.on 'finish', ->
150
- # get a blob you can do whatever you like with
151
- blob = stream.toBlob('application/pdf')
152
-
153
- # or get a blob URL for display in the browser
154
- url = stream.toBlobURL('application/pdf')
155
- iframe.src = url
156
- ```
157
-
158
- You can see an interactive in-browser demo of PDFKit [here](http://pdfkit.org/demo/browser.html).
159
-
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.
163
- If you forget to install it, Browserify will print an error message.
164
-
165
- ## Documentation
166
-
167
- For complete API documentation and more examples, see the [PDFKit website](http://pdfkit.org/).
168
-
169
- ## License
170
-
171
- PDFKit is available under the MIT license.
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
+ Installation uses the [npm](http://npmjs.org/) package manager. Just type the following command after installing npm.
22
+
23
+ npm install pdfkit
24
+
25
+ ## Features
26
+
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
+ * Outlines
50
+ * PDF security
51
+ * Encryption
52
+ * Access privileges (printing, copying, modifying, annotating, form filling, content accessibility, document assembly)
53
+
54
+ ## Coming soon!
55
+
56
+ * Patterns fills
57
+ * Higher level APIs for creating tables and laying out content
58
+ * More performance optimizations
59
+ * Even more awesomeness, perhaps written by you! Please fork this repository and send me pull requests.
60
+
61
+ ## Example
62
+
63
+ ```javascript
64
+ const PDFDocument = require('pdfkit');
65
+ const fs = require('fs');
66
+
67
+ // Create a document
68
+ const doc = new PDFDocument();
69
+
70
+ // Pipe its output somewhere, like to a file or HTTP response
71
+ // See below for browser usage
72
+ doc.pipe(fs.createWriteStream('output.pdf'));
73
+
74
+ // Embed a font, set the font size, and render some text
75
+ doc.font('fonts/PalatinoBold.ttf')
76
+ .fontSize(25)
77
+ .text('Some text with an embedded font!', 100, 100);
78
+
79
+ // Add an image, constrain it to a given size, and center it vertically and horizontally
80
+ doc.image('path/to/image.png', {
81
+ fit: [250, 300],
82
+ align: 'center',
83
+ valign: 'center'
84
+ });
85
+
86
+ // Add another page
87
+ doc.addPage()
88
+ .fontSize(25)
89
+ .text('Here is some vector graphics...', 100, 100);
90
+
91
+ // Draw a triangle
92
+ doc.save()
93
+ .moveTo(100, 150)
94
+ .lineTo(100, 250)
95
+ .lineTo(200, 250)
96
+ .fill("#FF3300");
97
+
98
+ // Apply some transforms and render an SVG path with the 'even-odd' fill rule
99
+ doc.scale(0.6)
100
+ .translate(470, -380)
101
+ .path('M 250,75 L 323,301 131,161 369,161 177,301 z')
102
+ .fill('red', 'even-odd')
103
+ .restore();
104
+
105
+ // Add some text with annotations
106
+ doc.addPage()
107
+ .fillColor("blue")
108
+ .text('Here is a link!', 100, 100)
109
+ .underline(100, 100, 160, 27, {color: "#0000FF"})
110
+ .link(100, 100, 160, 27, 'http://google.com/');
111
+
112
+ // Finalize PDF file
113
+ doc.end();
114
+ ```
115
+
116
+ [The PDF output from this example](http://pdfkit.org/demo/out.pdf) (with a few additions) shows the power of PDFKit producing
117
+ complex documents with a very small amount of code. For more, see the `demo` folder and the
118
+ [PDFKit programming guide](http://pdfkit.org/docs/getting_started.html).
119
+
120
+ ## Browser Usage
121
+
122
+ There are three ways to use PDFKit in the browser:
123
+ - 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)
124
+ - Use [webpack](https://webpack.js.org/). See [complete example](https://github.com/blikblum/pdfkit-webpack-example).
125
+ - Use prebuilt version. Distributed as `js/pdfkit.standalone.js` file in package.
126
+
127
+
128
+ In addition to PDFKit, you'll need somewhere to stream the output to. HTML5 has a
129
+ [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob) object which can be used to store binary data, and
130
+ get URLs to this data in order to display PDF output inside an iframe, or upload to a server, etc. In order to
131
+ get a Blob from the output of PDFKit, you can use the [blob-stream](https://github.com/devongovett/blob-stream)
132
+ module.
133
+
134
+ The following example uses Browserify or webpack to load `PDFKit` and `blob-stream`, but if you're not using Browserify,
135
+ you can load them in whatever way you'd like (e.g. script tags).
136
+
137
+ ```javascript
138
+ // require dependencies
139
+ const PDFDocument = require('pdfkit');
140
+ const blobStream = require('blob-stream');
141
+
142
+ // create a document the same way as above
143
+ const doc = new PDFDocument();
144
+
145
+ // pipe the document to a blob
146
+ const stream = doc.pipe(blobStream());
147
+
148
+ // add your content to the document here, as usual
149
+
150
+ // get a blob when you're done
151
+ doc.end();
152
+ stream.on('finish', function() {
153
+ // get a blob you can do whatever you like with
154
+ const blob = stream.toBlob('application/pdf');
155
+
156
+ // or get a blob URL for display in the browser
157
+ const url = stream.toBlobURL('application/pdf');
158
+ iframe.src = url;
159
+ });
160
+ ```
161
+
162
+ You can see an interactive in-browser demo of PDFKit [here](http://pdfkit.org/demo/browser.html).
163
+
164
+ Note that in order to Browserify a project using PDFKit, you need to install the `brfs` module with npm,
165
+ which is used to load built-in font data into the package. It is listed as a `devDependency` in
166
+ PDFKit's `package.json`, so it isn't installed by default for Node users.
167
+ If you forget to install it, Browserify will print an error message.
168
+
169
+ ## Documentation
170
+
171
+ For complete API documentation and more examples, see the [PDFKit website](http://pdfkit.org/).
172
+
173
+ ## License
174
+
175
+ PDFKit is available under the MIT license.