pdfv8 0.0.1
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/.cursor/settings.json +7 -0
- package/CHANGELOG.md +148 -0
- package/LICENSE +8 -0
- package/README.md +195 -0
- package/bun.lock +1549 -0
- package/js/pdfkit.es.js +498 -0
- package/js/pdfkit.es.js.map +1 -0
- package/js/pdfkit.js +500 -0
- package/js/pdfkit.js.map +1 -0
- package/js/pdfkit.standalone.js +49525 -0
- package/js/virtual-fs.js +95 -0
- package/jsconfig.json +13 -0
- package/package.json +102 -0
- package/scripts/gen-afm-data.mjs +41 -0
- package/tsconfig.build.json +23 -0
- package/types/abstract_reference.d.ts +4 -0
- package/types/crypto/aes.d.ts +2 -0
- package/types/crypto/md5.d.ts +2 -0
- package/types/crypto/random.d.ts +1 -0
- package/types/crypto/rc4.d.ts +1 -0
- package/types/crypto/sha256.d.ts +1 -0
- package/types/data.d.ts +29 -0
- package/types/document.d.ts +25 -0
- package/types/font/afm.d.ts +21 -0
- package/types/font/afm_data.generated.d.ts +1 -0
- package/types/font/embedded.d.ts +12 -0
- package/types/font/standard.d.ts +12 -0
- package/types/font.d.ts +10 -0
- package/types/font_factory.d.ts +6 -0
- package/types/gradient.d.ts +23 -0
- package/types/image/jpeg.d.ts +5 -0
- package/types/image/png.d.ts +9 -0
- package/types/image.d.ts +6 -0
- package/types/jest.custom-matchers.d.ts +28 -0
- package/types/line_wrapper.d.ts +10 -0
- package/types/metadata.d.ts +9 -0
- package/types/mixins/acroform.d.ts +48 -0
- package/types/mixins/annotations.d.ts +17 -0
- package/types/mixins/attachments.d.ts +17 -0
- package/types/mixins/color.d.ts +39 -0
- package/types/mixins/fonts.d.ts +19 -0
- package/types/mixins/images.d.ts +6 -0
- package/types/mixins/markings.d.ts +19 -0
- package/types/mixins/metadata.d.ts +7 -0
- package/types/mixins/outline.d.ts +5 -0
- package/types/mixins/pdfa.d.ts +9 -0
- package/types/mixins/pdfua.d.ts +7 -0
- package/types/mixins/subsets.d.ts +5 -0
- package/types/mixins/table.d.ts +11 -0
- package/types/mixins/text.d.ts +31 -0
- package/types/mixins/vector.d.ts +43 -0
- package/types/name_tree.d.ts +7 -0
- package/types/number_tree.d.ts +7 -0
- package/types/object.d.ts +5 -0
- package/types/outline.d.ts +20 -0
- package/types/page.d.ts +27 -0
- package/types/path.d.ts +4 -0
- package/types/pattern.d.ts +12 -0
- package/types/reference.d.ts +9 -0
- package/types/saslprep/index.d.ts +9 -0
- package/types/security.d.ts +12 -0
- package/types/spotcolor.d.ts +4 -0
- package/types/structure_annotation.d.ts +4 -0
- package/types/structure_content.d.ts +5 -0
- package/types/structure_element.d.ts +15 -0
- package/types/table/accessibility.d.ts +38 -0
- package/types/table/index.d.ts +23 -0
- package/types/table/normalize.d.ts +41 -0
- package/types/table/render.d.ts +10 -0
- package/types/table/size.d.ts +23 -0
- package/types/table/style.d.ts +48 -0
- package/types/table/utils.d.ts +303 -0
- package/types/tree.d.ts +10 -0
- package/types/utils.d.ts +64 -0
- package/types/virtual-fs.d.ts +8 -0
- package/types.d.ts +1128 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
## pdfkit changelog
|
|
2
|
+
|
|
3
|
+
### Unreleased
|
|
4
|
+
|
|
5
|
+
- Fix garbled text copying in Chrome/Edge for PDFs with >256 unique characters (#1659)
|
|
6
|
+
- Fix Link accessibility issues
|
|
7
|
+
- Fix Table Accessibility Issue: Operator CS/cs not allowed in this current state
|
|
8
|
+
- Fix Interlaced PNG with indexed transparency rendered incorrectly
|
|
9
|
+
- Fix SVG path parser incorrectly handle arc flags without separators
|
|
10
|
+
- Add pageLayout option to control how pages are displayed in PDF viewers
|
|
11
|
+
- Preserve existing PageMode instead of overwriting when adding outlines
|
|
12
|
+
- Add userUnit option for custom page units (PDF 1.6)
|
|
13
|
+
- Support outlines that jump to specific page positions with custom zoom level
|
|
14
|
+
- Add robust handling of null byte padding in JPEG images
|
|
15
|
+
- Replace outdated jpeg-exif with minimal implementation
|
|
16
|
+
- Replace outdated crypto-js with maintained small alternatives
|
|
17
|
+
- Fix issue with indentation with `indentAllLines: true` when a new page is created
|
|
18
|
+
|
|
19
|
+
### [v0.17.2] - 2025-08-30
|
|
20
|
+
|
|
21
|
+
- Fix rendering lists that spans across pages
|
|
22
|
+
|
|
23
|
+
### [v0.17.1] - 2025-05-02
|
|
24
|
+
|
|
25
|
+
- Fix null values in table cells rendering as `[object Object]`
|
|
26
|
+
- Fix further LineWrapper precision issues
|
|
27
|
+
- Optmize standard font handling. Less code, less memory usage
|
|
28
|
+
|
|
29
|
+
### [v0.17.0] - 2025-04-12
|
|
30
|
+
|
|
31
|
+
- Fix precision rounding issues in LineWrapper
|
|
32
|
+
- Fix fonts without a postscriptName
|
|
33
|
+
- Add support for dynamic sizing
|
|
34
|
+
- Add support for rotatable text
|
|
35
|
+
- Fix page cascade options when text overflows
|
|
36
|
+
- Add table generation
|
|
37
|
+
- Fix y position when using `image()` without x and y coordinates
|
|
38
|
+
- Improve Prettier configuration
|
|
39
|
+
|
|
40
|
+
### [v0.16.0] - 2024-12-29
|
|
41
|
+
|
|
42
|
+
- Update fontkit to 2.0
|
|
43
|
+
- Update linebreak to 1.1
|
|
44
|
+
- Add support for spot colors
|
|
45
|
+
- Add support to scale text horizontally
|
|
46
|
+
- Add an option to keep the indentation after a new line starts and allow to indent a whole paragraph/text element
|
|
47
|
+
- Add `Name` property for set custom icon for `note()`
|
|
48
|
+
- Fix sets tab order to "Structure" when a document is tagged
|
|
49
|
+
- Fix font cache collision for fonts with missing postscript name or bad TTF metadata or identical metadata for different fonts
|
|
50
|
+
- Fix for embedding fonts into PDF (font name must not contain spaces)
|
|
51
|
+
- Fix measuring text when OpenType features are passed in to .text()
|
|
52
|
+
|
|
53
|
+
### [v0.15.2] - 2024-12-15
|
|
54
|
+
|
|
55
|
+
- Fix index not counting when rendering ordered lists (#1517)
|
|
56
|
+
- Fix PDF/A3 compliance of attachments
|
|
57
|
+
- Fix CIDSet generation only for PDF/A1 subset
|
|
58
|
+
- Fix missing acroform font dictionary
|
|
59
|
+
- Fix modify time comparison check equality embedded files
|
|
60
|
+
|
|
61
|
+
### [v0.15.1] - 2024-10-30
|
|
62
|
+
|
|
63
|
+
- Fix browserify transform sRGB_IEC61966_2_1.icc file
|
|
64
|
+
- Fix time comparison check equality embedded files
|
|
65
|
+
|
|
66
|
+
### [v0.15.0] - 2024-03-23
|
|
67
|
+
|
|
68
|
+
- Add subset for PDF/UA
|
|
69
|
+
- Fix for line breaks in list items (#1486)
|
|
70
|
+
- Fix for soft hyphen not being replaced by visible hyphen if necessary (#457)
|
|
71
|
+
- Optimize output files by ignoring identity transforms
|
|
72
|
+
- Fix for Acroforms - setting an option to false will still apply the flag (#1495)
|
|
73
|
+
- Fix for text extraction in PDFium-based viewers due to invalid ToUnicodeMap (#1498)
|
|
74
|
+
- Remove deprecated `write` method
|
|
75
|
+
- Drop support for Node.js < 18 and for browsers released before 2020
|
|
76
|
+
|
|
77
|
+
### [v0.14.0] - 2023-11-09
|
|
78
|
+
|
|
79
|
+
- Add support for PDF/A-1b, PDF/A-1a, PDF/A-2b, PDF/A-2a, PDF/A-3b, PDF/A-3a
|
|
80
|
+
- Update crypto-js to v4.2.0 (properly fix security issue)
|
|
81
|
+
|
|
82
|
+
- Add support for EXIF orientation on JPEG images (#626 and #1353)
|
|
83
|
+
|
|
84
|
+
### [v0.13.0] - 2021-10-24
|
|
85
|
+
|
|
86
|
+
- Add tiling pattern support
|
|
87
|
+
|
|
88
|
+
### [v0.12.3] - 2021-08-01
|
|
89
|
+
|
|
90
|
+
- Remove examples from published package
|
|
91
|
+
|
|
92
|
+
### [v0.12.2] - 2021-08-01
|
|
93
|
+
|
|
94
|
+
- Fix for PDF accessibility check. (#1265)
|
|
95
|
+
- Allow applying 'underline' and 'strike' text styling together on a text
|
|
96
|
+
- Allow to specify the AcroForm text fontSize
|
|
97
|
+
- Update crypto-js to v4.0 (properly fix security issue)
|
|
98
|
+
|
|
99
|
+
### [v0.12.1] - 2021-04-10
|
|
100
|
+
|
|
101
|
+
- Update crypto-js to v3.3 (fix security issue)
|
|
102
|
+
- Update fontkit to 1.8.1
|
|
103
|
+
|
|
104
|
+
### [v0.12.0] - 2021-04-04
|
|
105
|
+
|
|
106
|
+
- Add support for Embedded Files and File Attachment Annotations
|
|
107
|
+
- Accessibility support
|
|
108
|
+
- Replace integration tests by visual regression tests
|
|
109
|
+
- Fix access permissions in PDF version 1.7ext3
|
|
110
|
+
- Fix Buffer() is deprecation warning
|
|
111
|
+
- Add `forms.md` to generate documentation files
|
|
112
|
+
- Fix "@" in FontName
|
|
113
|
+
|
|
114
|
+
### [v0.11.0] - 2019-12-03
|
|
115
|
+
|
|
116
|
+
- Fix infinite loop when an individual character is bigger than the width of the text.
|
|
117
|
+
- Fix infinite loop when text is positioned after page right margin
|
|
118
|
+
- Allow links in continued text to be stopped by setting link to null
|
|
119
|
+
- Add support to interlaced PNG files
|
|
120
|
+
- Do not emit \_interopDefault helper in commonjs build
|
|
121
|
+
- Fix gradient with multiple stops (#1045)
|
|
122
|
+
- Set link annotation flag to print by default
|
|
123
|
+
- Add support for AcroForms
|
|
124
|
+
- Drop support for (uncommon) cid less fonts on standalone build (reduces bundle size)
|
|
125
|
+
|
|
126
|
+
### [v0.10.0] - 2019-06-06
|
|
127
|
+
|
|
128
|
+
- Fix links to pages within the document
|
|
129
|
+
- Add support for named destinations
|
|
130
|
+
- Throw errors when `dash(...)` is passed invalid lengths
|
|
131
|
+
- Remove PDFDocument#output method
|
|
132
|
+
- Add standalone build (js/pdfkit.standalone.js)
|
|
133
|
+
|
|
134
|
+
### [v0.9.1] - 2019-04-30
|
|
135
|
+
|
|
136
|
+
- Fix setting printing permission
|
|
137
|
+
- Fix corruption of string objects in browser
|
|
138
|
+
- Add option to set default font
|
|
139
|
+
- Remove call to fontkit.openSync
|
|
140
|
+
- Add standalone virtual file system implementation
|
|
141
|
+
- Add option (fontLayoutCache) to disable font layout cache
|
|
142
|
+
|
|
143
|
+
### [v0.9.0] - 2019-01-28
|
|
144
|
+
|
|
145
|
+
- Convert to code base from coffescript to ES6+
|
|
146
|
+
- Fix loading grayscale / transparent PNG files
|
|
147
|
+
- Reduce number of calls to async functions
|
|
148
|
+
- Implement encryption / access control
|
package/LICENSE
ADDED
|
@@ -0,0 +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
|
+
|
|
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
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
# PDFV8
|
|
2
|
+
|
|
3
|
+
A JavaScript PDF generation library for Cloudflare Workers (Edge).
|
|
4
|
+
|
|
5
|
+
## Description
|
|
6
|
+
|
|
7
|
+
PDFV8 is a PDF document generation library designed to run on the Edge (Cloudflare Workers). The API embraces
|
|
8
|
+
chainability, and includes both low level functions as well as abstractions for higher level functionality.
|
|
9
|
+
|
|
10
|
+
See the docs in [`docs/`](docs/) and the Worker-focused setup in “Cloudflare Workers Usage” below.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
Use [npm](http://npmjs.org/), [yarn](https://yarnpkg.com/), or [bun](https://bun.sh/) package manager. Just type the following command:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
# with npm
|
|
18
|
+
npm install cloudflare-pdf
|
|
19
|
+
|
|
20
|
+
# with yarn
|
|
21
|
+
yarn add cloudflare-pdf
|
|
22
|
+
|
|
23
|
+
# with bun
|
|
24
|
+
bun add cloudflare-pdf
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Development
|
|
28
|
+
|
|
29
|
+
To run tests (Jest), use the package script so the correct runner is used:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npm test
|
|
33
|
+
# or with bun (use "bun run test", not "bun test")
|
|
34
|
+
bun run test
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Features
|
|
38
|
+
|
|
39
|
+
- Vector graphics
|
|
40
|
+
- HTML5 canvas-like API
|
|
41
|
+
- Path operations
|
|
42
|
+
- SVG path parser for easy path creation
|
|
43
|
+
- Transformations
|
|
44
|
+
- Linear and radial gradients
|
|
45
|
+
- Text
|
|
46
|
+
- Line wrapping (with soft hyphen recognition)
|
|
47
|
+
- Text alignments
|
|
48
|
+
- Bulleted lists
|
|
49
|
+
- Font embedding
|
|
50
|
+
- Supports TrueType (.ttf), OpenType (.otf), WOFF, WOFF2, TrueType Collections (.ttc), and Datafork TrueType (.dfont) fonts
|
|
51
|
+
- Font subsetting
|
|
52
|
+
- See [fontkit](http://github.com/foliojs/fontkit) for more details on advanced glyph layout support.
|
|
53
|
+
- Image embedding
|
|
54
|
+
- Supports JPEG and PNG files (including indexed PNGs, and PNGs with transparency)
|
|
55
|
+
- Tables
|
|
56
|
+
- Annotations
|
|
57
|
+
- Links
|
|
58
|
+
- Notes
|
|
59
|
+
- Highlights
|
|
60
|
+
- Underlines
|
|
61
|
+
- etc.
|
|
62
|
+
- AcroForms
|
|
63
|
+
- Outlines
|
|
64
|
+
- PDF security
|
|
65
|
+
- Encryption
|
|
66
|
+
- Access privileges (printing, copying, modifying, annotating, form filling, content accessibility, document assembly)
|
|
67
|
+
- Accessibility support (marked content, logical structure, Tagged PDF, PDF/UA)
|
|
68
|
+
|
|
69
|
+
## Coming soon!
|
|
70
|
+
|
|
71
|
+
- Patterns fills
|
|
72
|
+
- Higher level APIs for laying out content
|
|
73
|
+
- More performance optimizations
|
|
74
|
+
- Even more awesomeness, perhaps written by you! Please fork this repository and send me pull requests.
|
|
75
|
+
|
|
76
|
+
## Example (Cloudflare Workers)
|
|
77
|
+
|
|
78
|
+
```javascript
|
|
79
|
+
const PDFDocument = require('cloudflare-pdf');
|
|
80
|
+
|
|
81
|
+
const doc = new PDFDocument();
|
|
82
|
+
|
|
83
|
+
// Collect output into an ArrayBuffer (Workers)
|
|
84
|
+
const chunks = [];
|
|
85
|
+
doc.on('data', (c) => chunks.push(c));
|
|
86
|
+
const pdfDone = new Promise((resolve) => doc.on('end', resolve));
|
|
87
|
+
|
|
88
|
+
// Embed a font, set the font size, and render some text
|
|
89
|
+
doc
|
|
90
|
+
// Use standard fonts after preloading them (see below), or pass ArrayBuffer/Uint8Array for embedded fonts.
|
|
91
|
+
.font('Helvetica-Bold')
|
|
92
|
+
.fontSize(25)
|
|
93
|
+
.text('Some text with an embedded font!', 100, 100);
|
|
94
|
+
|
|
95
|
+
// Add an image, constrain it to a given size, and center it vertically and horizontally
|
|
96
|
+
doc.image('path/to/image.png', {
|
|
97
|
+
fit: [250, 300],
|
|
98
|
+
align: 'center',
|
|
99
|
+
valign: 'center'
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// Add another page
|
|
103
|
+
doc
|
|
104
|
+
.addPage()
|
|
105
|
+
.fontSize(25)
|
|
106
|
+
.text('Here is some vector graphics...', 100, 100);
|
|
107
|
+
|
|
108
|
+
// Draw a triangle
|
|
109
|
+
doc
|
|
110
|
+
.save()
|
|
111
|
+
.moveTo(100, 150)
|
|
112
|
+
.lineTo(100, 250)
|
|
113
|
+
.lineTo(200, 250)
|
|
114
|
+
.fill('#FF3300');
|
|
115
|
+
|
|
116
|
+
// Apply some transforms and render an SVG path with the 'even-odd' fill rule
|
|
117
|
+
doc
|
|
118
|
+
.scale(0.6)
|
|
119
|
+
.translate(470, -380)
|
|
120
|
+
.path('M 250,75 L 323,301 131,161 369,161 177,301 z')
|
|
121
|
+
.fill('red', 'even-odd')
|
|
122
|
+
.restore();
|
|
123
|
+
|
|
124
|
+
// Add some text with annotations
|
|
125
|
+
doc
|
|
126
|
+
.addPage()
|
|
127
|
+
.fillColor('blue')
|
|
128
|
+
.text('Here is a link!', 100, 100)
|
|
129
|
+
.underline(100, 100, 160, 27, { color: '#0000FF' })
|
|
130
|
+
.link(100, 100, 160, 27, 'http://google.com/');
|
|
131
|
+
|
|
132
|
+
// Finalize PDF file
|
|
133
|
+
doc.end();
|
|
134
|
+
|
|
135
|
+
await pdfDone;
|
|
136
|
+
const pdf = new Blob(chunks, { type: 'application/pdf' });
|
|
137
|
+
return new Response(pdf, { headers: { 'content-type': 'application/pdf' } });
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Cloudflare Workers Usage
|
|
141
|
+
|
|
142
|
+
- **Standard fonts** (Helvetica, Times, Courier, etc.) are not loaded by default. Preload them once at startup:
|
|
143
|
+
|
|
144
|
+
```javascript
|
|
145
|
+
const StandardFont = require('cloudflare-pdf/lib/font/standard').default;
|
|
146
|
+
await StandardFont.preload(); // or await StandardFont.preload(['Helvetica', 'Helvetica-Bold'])
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
- **Embedded fonts**: pass `ArrayBuffer`/`Uint8Array` (for example from `R2.get(...).arrayBuffer()`).
|
|
150
|
+
|
|
151
|
+
In addition to PDFKit, you'll need somewhere to stream the output to. HTML5 has a
|
|
152
|
+
[Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob) object which can be used to store binary data, and
|
|
153
|
+
get URLs to this data in order to display PDF output inside an iframe, or upload to a server, etc. In order to
|
|
154
|
+
get a Blob from the output of PDFKit, you can use the [blob-stream](https://github.com/devongovett/blob-stream)
|
|
155
|
+
module.
|
|
156
|
+
|
|
157
|
+
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
|
|
158
|
+
of prebuilt version usage.
|
|
159
|
+
|
|
160
|
+
```javascript
|
|
161
|
+
// require dependencies
|
|
162
|
+
const PDFDocument = require('pdfkit');
|
|
163
|
+
const blobStream = require('blob-stream');
|
|
164
|
+
|
|
165
|
+
// create a document the same way as above
|
|
166
|
+
const doc = new PDFDocument();
|
|
167
|
+
|
|
168
|
+
// pipe the document to a blob
|
|
169
|
+
const stream = doc.pipe(blobStream());
|
|
170
|
+
|
|
171
|
+
// add your content to the document here, as usual
|
|
172
|
+
|
|
173
|
+
// get a blob when you are done
|
|
174
|
+
doc.end();
|
|
175
|
+
stream.on('finish', function() {
|
|
176
|
+
// get a blob you can do whatever you like with
|
|
177
|
+
const blob = stream.toBlob('application/pdf');
|
|
178
|
+
|
|
179
|
+
// or get a blob URL for display in the browser
|
|
180
|
+
const url = stream.toBlobURL('application/pdf');
|
|
181
|
+
iframe.src = url;
|
|
182
|
+
});
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
You can see an interactive in-browser demo of PDFKit [here](http://pdfkit.org/demo/browser.html).
|
|
186
|
+
|
|
187
|
+
This package targets Edge runtimes; Node filesystem APIs are not used at runtime.
|
|
188
|
+
|
|
189
|
+
## Documentation
|
|
190
|
+
|
|
191
|
+
For complete API documentation and more examples, see the [PDFKit website](http://pdfkit.org/).
|
|
192
|
+
|
|
193
|
+
## License
|
|
194
|
+
|
|
195
|
+
PDFKit is available under the MIT license.
|