@flowaccount/pdfmake 1.0.4-staging.2 → 1.0.5-staging.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/LICENSE +21 -21
- package/README.md +297 -297
- package/build/pdfmake.js +45181 -44698
- package/build/pdfmake.min.js +2 -2
- package/build/pdfmake.min.js.map +1 -1
- package/build/vfs_fonts.js +6 -6
- package/package.json +110 -110
- package/src/3rd-party/svg-to-pdfkit.js +3 -3
- package/src/browser-extensions/URLBrowserResolver.js +96 -96
- package/src/browser-extensions/pdfMake.js +361 -361
- package/src/browser-extensions/tokenizer-shim.js +15 -15
- package/src/browser-extensions/virtual-fs.js +55 -55
- package/src/columnCalculator.js +157 -157
- package/src/docMeasure.js +831 -831
- package/src/docPreprocessor.js +277 -277
- package/src/documentContext.js +383 -383
- package/src/elementWriter.js +434 -434
- package/src/fontProvider.js +68 -68
- package/src/helpers.js +138 -138
- package/src/imageMeasure.js +70 -70
- package/src/layoutBuilder.js +1770 -1770
- package/src/line.js +91 -91
- package/src/pageElementWriter.js +362 -362
- package/src/pdfKitEngine.js +21 -21
- package/src/printer.js +1191 -1191
- package/src/qrEnc.js +790 -790
- package/src/standardPageSizes.js +54 -54
- package/src/styleContextStack.js +138 -138
- package/src/svgMeasure.js +70 -70
- package/src/tableProcessor.js +789 -784
- package/src/textDecorator.js +157 -157
- package/src/textTools.js +442 -442
- package/src/traversalTracker.js +47 -47
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2014-2015 bpampuch
|
|
4
|
-
2016-2025 liborm85
|
|
5
|
-
|
|
6
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
7
|
-
this software and associated documentation files (the "Software"), to deal in
|
|
8
|
-
the Software without restriction, including without limitation the rights to
|
|
9
|
-
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
10
|
-
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
11
|
-
subject to the following conditions:
|
|
12
|
-
|
|
13
|
-
The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
copies or substantial portions of the Software.
|
|
15
|
-
|
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
18
|
-
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
19
|
-
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
20
|
-
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
21
|
-
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2014-2015 bpampuch
|
|
4
|
+
2016-2025 liborm85
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
7
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
8
|
+
the Software without restriction, including without limitation the rights to
|
|
9
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
10
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
11
|
+
subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
18
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
19
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
20
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
21
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,297 +1,297 @@
|
|
|
1
|
-
# pdfmake [![Node.js CI][githubactions_img]][githubactions_url] [![GitHub][github_img]][github_url] [![npm][npm_img]][npm_url] [![Bower][bower_img]][bower_url] [![Packagist][packagist_img]][packagist_url] [![CDNJS][cdnjs_img]][cndjs_url]
|
|
2
|
-
|
|
3
|
-
[githubactions_img]: https://github.com/bpampuch/pdfmake/actions/workflows/node.js.yml/badge.svg?branch=0.2
|
|
4
|
-
[githubactions_url]: https://github.com/bpampuch/pdfmake/actions
|
|
5
|
-
|
|
6
|
-
[github_img]: https://img.shields.io/github/release/bpampuch/pdfmake.svg?colorB=0E7FBF
|
|
7
|
-
[github_url]: https://github.com/bpampuch/pdfmake/releases/latest
|
|
8
|
-
|
|
9
|
-
[npm_img]: https://img.shields.io/npm/v/pdfmake.svg?colorB=0E7FBF
|
|
10
|
-
[npm_url]: https://www.npmjs.com/package/pdfmake
|
|
11
|
-
|
|
12
|
-
[bower_img]: https://img.shields.io/bower/v/pdfmake.svg?colorB=0E7FBF
|
|
13
|
-
[bower_url]: https://github.com/bpampuch/pdfmake
|
|
14
|
-
|
|
15
|
-
[packagist_img]: https://img.shields.io/packagist/v/bpampuch/pdfmake.svg?colorB=0E7FBF
|
|
16
|
-
[packagist_url]: https://packagist.org/packages/bpampuch/pdfmake
|
|
17
|
-
|
|
18
|
-
[cdnjs_img]: https://img.shields.io/cdnjs/v/pdfmake.svg?colorB=0E7FBF
|
|
19
|
-
[cndjs_url]: https://cdnjs.com/libraries/pdfmake
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
PDF document generation library for server-side and client-side usage in pure JavaScript.
|
|
23
|
-
|
|
24
|
-
Check out [the playground](http://bpampuch.github.io/pdfmake/playground.html) and [examples](https://github.com/bpampuch/pdfmake/tree/0.1/examples).
|
|
25
|
-
|
|
26
|
-
### Features
|
|
27
|
-
|
|
28
|
-
* line-wrapping,
|
|
29
|
-
* text-alignments (left, right, centered, justified),
|
|
30
|
-
* numbered and bulleted lists,
|
|
31
|
-
* tables and columns
|
|
32
|
-
* auto/fixed/star-sized widths,
|
|
33
|
-
* col-spans and row-spans,
|
|
34
|
-
* headers automatically repeated in case of a page-break,
|
|
35
|
-
* images and vector graphics,
|
|
36
|
-
* convenient styling and style inheritance,
|
|
37
|
-
* page headers and footers:
|
|
38
|
-
* static or dynamic content,
|
|
39
|
-
* access to current page number and page count,
|
|
40
|
-
* background-layer,
|
|
41
|
-
* page dimensions and orientations,
|
|
42
|
-
* margins,
|
|
43
|
-
* custom page breaks,
|
|
44
|
-
* font embedding,
|
|
45
|
-
* support for complex, multi-level (nested) structures,
|
|
46
|
-
* table of contents,
|
|
47
|
-
* helper methods for opening/printing/downloading the generated PDF,
|
|
48
|
-
* setting of PDF metadata (e.g. author, subject).
|
|
49
|
-
|
|
50
|
-
## Documentation
|
|
51
|
-
|
|
52
|
-
Documentation URL: https://pdfmake.github.io/docs/
|
|
53
|
-
|
|
54
|
-
## Building from sources version 0.2.x
|
|
55
|
-
|
|
56
|
-
using npm:
|
|
57
|
-
```
|
|
58
|
-
git clone --branch 0.2 https://github.com/bpampuch/pdfmake.git
|
|
59
|
-
cd pdfmake
|
|
60
|
-
npm install
|
|
61
|
-
npm run build
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
using yarn:
|
|
65
|
-
```
|
|
66
|
-
git clone --branch 0.2 https://github.com/bpampuch/pdfmake.git
|
|
67
|
-
cd pdfmake
|
|
68
|
-
yarn
|
|
69
|
-
yarn run build
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
## Deployment (FlowAccount Fork)
|
|
73
|
-
|
|
74
|
-
### Prerequisites
|
|
75
|
-
|
|
76
|
-
Before deploying, ensure you have:
|
|
77
|
-
- Node.js >= 18
|
|
78
|
-
- npm authentication configured for FlowAccount organization
|
|
79
|
-
- Proper access rights to publish `@flowaccount/pdfmake` package
|
|
80
|
-
|
|
81
|
-
### NPM Authentication
|
|
82
|
-
|
|
83
|
-
Configure your npm authentication token:
|
|
84
|
-
|
|
85
|
-
```bash
|
|
86
|
-
npm login
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
Or set up your `.npmrc` file with your authentication token:
|
|
90
|
-
|
|
91
|
-
```bash
|
|
92
|
-
# ~/.npmrc or project .npmrc
|
|
93
|
-
//registry.npmjs.org/:_authToken=YOUR_NPM_TOKEN
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
### Staging Deployment
|
|
97
|
-
|
|
98
|
-
Deploy a pre-release version for staging/testing:
|
|
99
|
-
|
|
100
|
-
```bash
|
|
101
|
-
npm run publish:staging
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
**What this does:**
|
|
105
|
-
1. Builds the project (`npm run build`)
|
|
106
|
-
2. Runs all tests (`npm run test`)
|
|
107
|
-
3. Automatically bumps version to next prerelease (e.g., `0.2.20-staging.1` → `0.2.20-staging.2`)
|
|
108
|
-
4. Publishes to npm with `staging` tag
|
|
109
|
-
5. Package published as `@flowaccount/pdfmake@staging`
|
|
110
|
-
|
|
111
|
-
**Install staging version:**
|
|
112
|
-
```bash
|
|
113
|
-
npm install @flowaccount/pdfmake@staging
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
**View staging versions:**
|
|
117
|
-
```bash
|
|
118
|
-
npm view @flowaccount/pdfmake versions --tag staging
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
### Production Deployment
|
|
122
|
-
|
|
123
|
-
Deploy a stable production release:
|
|
124
|
-
|
|
125
|
-
#### Step 1: Version Bump (choose one)
|
|
126
|
-
|
|
127
|
-
**Patch version** (bug fixes: 0.2.20 → 0.2.21):
|
|
128
|
-
```bash
|
|
129
|
-
npm run version:patch
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
**Minor version** (new features, backward compatible: 0.2.20 → 0.3.0):
|
|
133
|
-
```bash
|
|
134
|
-
npm run version:minor
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
**Major version** (breaking changes: 0.2.20 → 1.0.0):
|
|
138
|
-
```bash
|
|
139
|
-
npm run version:major
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
#### Step 2: Commit and Tag
|
|
143
|
-
|
|
144
|
-
```bash
|
|
145
|
-
git add package.json
|
|
146
|
-
git commit -m "chore: bump version to $(node -p "require('./package.json').version")"
|
|
147
|
-
git tag v$(node -p "require('./package.json').version")
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
#### Step 3: Publish to Production
|
|
151
|
-
|
|
152
|
-
```bash
|
|
153
|
-
npm run publish:production
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
**What this does:**
|
|
157
|
-
1. Builds the project (`npm run build`)
|
|
158
|
-
2. Runs all tests (`npm run test`)
|
|
159
|
-
3. Publishes to npm with `latest` tag (default)
|
|
160
|
-
4. Package published as `@flowaccount/pdfmake@latest`
|
|
161
|
-
|
|
162
|
-
#### Step 4: Push Changes and Tags
|
|
163
|
-
|
|
164
|
-
```bash
|
|
165
|
-
git push origin main
|
|
166
|
-
git push origin --tags
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
**Install production version:**
|
|
170
|
-
```bash
|
|
171
|
-
npm install @flowaccount/pdfmake
|
|
172
|
-
# or specific version
|
|
173
|
-
npm install @flowaccount/pdfmake@0.2.20
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
### Local Development Publishing
|
|
177
|
-
|
|
178
|
-
For testing npm package locally with Verdaccio or similar local registry:
|
|
179
|
-
|
|
180
|
-
```bash
|
|
181
|
-
npm run publish:local
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
This publishes to `http://localhost:4872` with a timestamp-based version.
|
|
185
|
-
|
|
186
|
-
### Deployment Checklist
|
|
187
|
-
|
|
188
|
-
- [ ] All tests passing (`npm test`)
|
|
189
|
-
- [ ] Code linted (`npm run lint`)
|
|
190
|
-
- [ ] Build successful (`npm run build`)
|
|
191
|
-
- [ ] CHANGELOG.md updated with changes
|
|
192
|
-
- [ ] Version bumped appropriately
|
|
193
|
-
- [ ] Git commit and tag created
|
|
194
|
-
- [ ] Package published successfully
|
|
195
|
-
- [ ] Git changes pushed to remote
|
|
196
|
-
- [ ] Release notes added on GitHub (optional)
|
|
197
|
-
- [ ] Team notified of new release
|
|
198
|
-
|
|
199
|
-
### Troubleshooting
|
|
200
|
-
|
|
201
|
-
**Permission Denied Error:**
|
|
202
|
-
```bash
|
|
203
|
-
npm ERR! code E403
|
|
204
|
-
npm ERR! 403 403 Forbidden - PUT https://registry.npmjs.org/@flowaccount%2fpdfmake
|
|
205
|
-
```
|
|
206
|
-
Solution: Ensure you're logged in with an account that has publish rights to `@flowaccount` organization.
|
|
207
|
-
|
|
208
|
-
**Version Already Exists:**
|
|
209
|
-
```bash
|
|
210
|
-
npm ERR! code E409
|
|
211
|
-
npm ERR! 409 Conflict - PUT https://registry.npmjs.org/@flowaccount%2fpdfmake
|
|
212
|
-
```
|
|
213
|
-
Solution: Bump the version number and try again.
|
|
214
|
-
|
|
215
|
-
**Build or Test Failures:**
|
|
216
|
-
If `publish:staging` or `publish:production` fails, the publish is automatically aborted. Fix the issues and retry.
|
|
217
|
-
|
|
218
|
-
### Version Management
|
|
219
|
-
|
|
220
|
-
Current version format: `MAJOR.MINOR.PATCH[-PRERELEASE]`
|
|
221
|
-
|
|
222
|
-
- **Production versions**: `0.2.20`, `0.2.21`, `0.3.0`
|
|
223
|
-
- **Staging versions**: `0.2.20-staging.1`, `0.2.20-staging.2`
|
|
224
|
-
- **Local versions**: `0.2.20-local.1730123456`
|
|
225
|
-
|
|
226
|
-
To check current published versions:
|
|
227
|
-
```bash
|
|
228
|
-
npm view @flowaccount/pdfmake versions
|
|
229
|
-
npm view @flowaccount/pdfmake dist-tags
|
|
230
|
-
```
|
|
231
|
-
|
|
232
|
-
## License
|
|
233
|
-
MIT
|
|
234
|
-
|
|
235
|
-
## Authors
|
|
236
|
-
* [@bpampuch](https://github.com/bpampuch) (founder)
|
|
237
|
-
* [@liborm85](https://github.com/liborm85)
|
|
238
|
-
|
|
239
|
-
pdfmake is based on a truly amazing library [pdfkit](https://github.com/devongovett/pdfkit) (credits to [@devongovett](https://github.com/devongovett)).
|
|
240
|
-
|
|
241
|
-
Thanks to all contributors.
|
|
242
|
-
|
|
243
|
-
---
|
|
244
|
-
|
|
245
|
-
## FlowAccount Customizations (Fork Notes)
|
|
246
|
-
|
|
247
|
-
This fork extends pdfmake 0.2.x with FlowAccount-specific features and behavior.
|
|
248
|
-
|
|
249
|
-
### 1. Remote Image URLs (Browser & Node)
|
|
250
|
-
You can now reference HTTP(S) image URLs directly in your `docDefinition.images` map or inline `image` properties.
|
|
251
|
-
|
|
252
|
-
Browser usage (helper auto-fetch):
|
|
253
|
-
```js
|
|
254
|
-
pdfMake.createPdf(docDefinition).download(); // remote image URLs resolved before layout
|
|
255
|
-
```
|
|
256
|
-
|
|
257
|
-
Node usage (async prefetch):
|
|
258
|
-
```js
|
|
259
|
-
const printer = new PdfPrinter(fonts);
|
|
260
|
-
await printer.resolveRemoteImages(docDefinition); // fetch & embed as data URLs
|
|
261
|
-
const pdfDoc = await printer.createPdfKitDocumentAsync(docDefinition, options);
|
|
262
|
-
pdfDoc.pipe(fs.createWriteStream('out.pdf'));
|
|
263
|
-
pdfDoc.end();
|
|
264
|
-
```
|
|
265
|
-
Errors while fetching images are swallowed (image omitted) so a bad URL will not abort PDF generation.
|
|
266
|
-
|
|
267
|
-
### 2. Dynamic Header/Footer Height Measurement
|
|
268
|
-
If your header or footer function returns variable-height content, the layout engine performs a preliminary measurement pass and adjusts `pageMargins.top` / `pageMargins.bottom` so body content starts after real header/footer height.
|
|
269
|
-
|
|
270
|
-
### 3. Vertical Alignment in Table Cells & Layers
|
|
271
|
-
Table cells and layered content can specify `verticalAlign: 'top'|'middle'|'bottom'` (same values as legacy implementation). Markers are inserted to compute and realign content after row height is known.
|
|
272
|
-
|
|
273
|
-
### 4. Layers
|
|
274
|
-
Any node can include `layers: [ nodeA, nodeB, ... ]`. Layers share the same starting Y position; the tallest layer determines consumed height. Useful for overlaying backgrounds/watermarks behind foreground text without manual positioning.
|
|
275
|
-
|
|
276
|
-
### 5. Remark Table Transformation
|
|
277
|
-
Legacy pattern: when `docStructure[2][0]` contains a `remark` table and is immediately followed by a detail node, these two nodes are transformed into added header rows inside the remark table for consistent page-break behavior.
|
|
278
|
-
|
|
279
|
-
### 6. footerBreak Logic
|
|
280
|
-
Nodes marked with `footerBreak: true` after the first such node are skipped (prevents duplicate footer sections when custom flows generate repeated fragments).
|
|
281
|
-
|
|
282
|
-
### 7. Async API Additions
|
|
283
|
-
`printer.resolveRemoteImages(docDefinition, timeoutMs?)` – fetch remote images and inline them.
|
|
284
|
-
|
|
285
|
-
`printer.createPdfKitDocumentAsync(docDefinition, options)` – async variant ensuring remote images (and any future async preprocessing) are complete before layout.
|
|
286
|
-
|
|
287
|
-
### 8. Development Helpers
|
|
288
|
-
Hot reload (playground) via `npm run dev:play` (nodemon + webpack watch) – see `dev-playground/README.md`.
|
|
289
|
-
|
|
290
|
-
### 9. Testing
|
|
291
|
-
Added unit tests covering remote image resolution and legacy layout customizations (`tests/layoutBuilder_legacy_custom.spec.js`).
|
|
292
|
-
|
|
293
|
-
### 10. Caveats
|
|
294
|
-
* Dynamic header/footer measurement is a heuristic single-pass; if header/footer height depends on total page count, final heights might differ slightly.
|
|
295
|
-
* Remote image fetching uses global `fetch`; ensure Node >= 18 or polyfill fetch in earlier runtimes.
|
|
296
|
-
|
|
297
|
-
---
|
|
1
|
+
# pdfmake [![Node.js CI][githubactions_img]][githubactions_url] [![GitHub][github_img]][github_url] [![npm][npm_img]][npm_url] [![Bower][bower_img]][bower_url] [![Packagist][packagist_img]][packagist_url] [![CDNJS][cdnjs_img]][cndjs_url]
|
|
2
|
+
|
|
3
|
+
[githubactions_img]: https://github.com/bpampuch/pdfmake/actions/workflows/node.js.yml/badge.svg?branch=0.2
|
|
4
|
+
[githubactions_url]: https://github.com/bpampuch/pdfmake/actions
|
|
5
|
+
|
|
6
|
+
[github_img]: https://img.shields.io/github/release/bpampuch/pdfmake.svg?colorB=0E7FBF
|
|
7
|
+
[github_url]: https://github.com/bpampuch/pdfmake/releases/latest
|
|
8
|
+
|
|
9
|
+
[npm_img]: https://img.shields.io/npm/v/pdfmake.svg?colorB=0E7FBF
|
|
10
|
+
[npm_url]: https://www.npmjs.com/package/pdfmake
|
|
11
|
+
|
|
12
|
+
[bower_img]: https://img.shields.io/bower/v/pdfmake.svg?colorB=0E7FBF
|
|
13
|
+
[bower_url]: https://github.com/bpampuch/pdfmake
|
|
14
|
+
|
|
15
|
+
[packagist_img]: https://img.shields.io/packagist/v/bpampuch/pdfmake.svg?colorB=0E7FBF
|
|
16
|
+
[packagist_url]: https://packagist.org/packages/bpampuch/pdfmake
|
|
17
|
+
|
|
18
|
+
[cdnjs_img]: https://img.shields.io/cdnjs/v/pdfmake.svg?colorB=0E7FBF
|
|
19
|
+
[cndjs_url]: https://cdnjs.com/libraries/pdfmake
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
PDF document generation library for server-side and client-side usage in pure JavaScript.
|
|
23
|
+
|
|
24
|
+
Check out [the playground](http://bpampuch.github.io/pdfmake/playground.html) and [examples](https://github.com/bpampuch/pdfmake/tree/0.1/examples).
|
|
25
|
+
|
|
26
|
+
### Features
|
|
27
|
+
|
|
28
|
+
* line-wrapping,
|
|
29
|
+
* text-alignments (left, right, centered, justified),
|
|
30
|
+
* numbered and bulleted lists,
|
|
31
|
+
* tables and columns
|
|
32
|
+
* auto/fixed/star-sized widths,
|
|
33
|
+
* col-spans and row-spans,
|
|
34
|
+
* headers automatically repeated in case of a page-break,
|
|
35
|
+
* images and vector graphics,
|
|
36
|
+
* convenient styling and style inheritance,
|
|
37
|
+
* page headers and footers:
|
|
38
|
+
* static or dynamic content,
|
|
39
|
+
* access to current page number and page count,
|
|
40
|
+
* background-layer,
|
|
41
|
+
* page dimensions and orientations,
|
|
42
|
+
* margins,
|
|
43
|
+
* custom page breaks,
|
|
44
|
+
* font embedding,
|
|
45
|
+
* support for complex, multi-level (nested) structures,
|
|
46
|
+
* table of contents,
|
|
47
|
+
* helper methods for opening/printing/downloading the generated PDF,
|
|
48
|
+
* setting of PDF metadata (e.g. author, subject).
|
|
49
|
+
|
|
50
|
+
## Documentation
|
|
51
|
+
|
|
52
|
+
Documentation URL: https://pdfmake.github.io/docs/
|
|
53
|
+
|
|
54
|
+
## Building from sources version 0.2.x
|
|
55
|
+
|
|
56
|
+
using npm:
|
|
57
|
+
```
|
|
58
|
+
git clone --branch 0.2 https://github.com/bpampuch/pdfmake.git
|
|
59
|
+
cd pdfmake
|
|
60
|
+
npm install
|
|
61
|
+
npm run build
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
using yarn:
|
|
65
|
+
```
|
|
66
|
+
git clone --branch 0.2 https://github.com/bpampuch/pdfmake.git
|
|
67
|
+
cd pdfmake
|
|
68
|
+
yarn
|
|
69
|
+
yarn run build
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Deployment (FlowAccount Fork)
|
|
73
|
+
|
|
74
|
+
### Prerequisites
|
|
75
|
+
|
|
76
|
+
Before deploying, ensure you have:
|
|
77
|
+
- Node.js >= 18
|
|
78
|
+
- npm authentication configured for FlowAccount organization
|
|
79
|
+
- Proper access rights to publish `@flowaccount/pdfmake` package
|
|
80
|
+
|
|
81
|
+
### NPM Authentication
|
|
82
|
+
|
|
83
|
+
Configure your npm authentication token:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
npm login
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Or set up your `.npmrc` file with your authentication token:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
# ~/.npmrc or project .npmrc
|
|
93
|
+
//registry.npmjs.org/:_authToken=YOUR_NPM_TOKEN
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Staging Deployment
|
|
97
|
+
|
|
98
|
+
Deploy a pre-release version for staging/testing:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
npm run publish:staging
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
**What this does:**
|
|
105
|
+
1. Builds the project (`npm run build`)
|
|
106
|
+
2. Runs all tests (`npm run test`)
|
|
107
|
+
3. Automatically bumps version to next prerelease (e.g., `0.2.20-staging.1` → `0.2.20-staging.2`)
|
|
108
|
+
4. Publishes to npm with `staging` tag
|
|
109
|
+
5. Package published as `@flowaccount/pdfmake@staging`
|
|
110
|
+
|
|
111
|
+
**Install staging version:**
|
|
112
|
+
```bash
|
|
113
|
+
npm install @flowaccount/pdfmake@staging
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
**View staging versions:**
|
|
117
|
+
```bash
|
|
118
|
+
npm view @flowaccount/pdfmake versions --tag staging
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Production Deployment
|
|
122
|
+
|
|
123
|
+
Deploy a stable production release:
|
|
124
|
+
|
|
125
|
+
#### Step 1: Version Bump (choose one)
|
|
126
|
+
|
|
127
|
+
**Patch version** (bug fixes: 0.2.20 → 0.2.21):
|
|
128
|
+
```bash
|
|
129
|
+
npm run version:patch
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
**Minor version** (new features, backward compatible: 0.2.20 → 0.3.0):
|
|
133
|
+
```bash
|
|
134
|
+
npm run version:minor
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
**Major version** (breaking changes: 0.2.20 → 1.0.0):
|
|
138
|
+
```bash
|
|
139
|
+
npm run version:major
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
#### Step 2: Commit and Tag
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
git add package.json
|
|
146
|
+
git commit -m "chore: bump version to $(node -p "require('./package.json').version")"
|
|
147
|
+
git tag v$(node -p "require('./package.json').version")
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
#### Step 3: Publish to Production
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
npm run publish:production
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
**What this does:**
|
|
157
|
+
1. Builds the project (`npm run build`)
|
|
158
|
+
2. Runs all tests (`npm run test`)
|
|
159
|
+
3. Publishes to npm with `latest` tag (default)
|
|
160
|
+
4. Package published as `@flowaccount/pdfmake@latest`
|
|
161
|
+
|
|
162
|
+
#### Step 4: Push Changes and Tags
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
git push origin main
|
|
166
|
+
git push origin --tags
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
**Install production version:**
|
|
170
|
+
```bash
|
|
171
|
+
npm install @flowaccount/pdfmake
|
|
172
|
+
# or specific version
|
|
173
|
+
npm install @flowaccount/pdfmake@0.2.20
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### Local Development Publishing
|
|
177
|
+
|
|
178
|
+
For testing npm package locally with Verdaccio or similar local registry:
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
npm run publish:local
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
This publishes to `http://localhost:4872` with a timestamp-based version.
|
|
185
|
+
|
|
186
|
+
### Deployment Checklist
|
|
187
|
+
|
|
188
|
+
- [ ] All tests passing (`npm test`)
|
|
189
|
+
- [ ] Code linted (`npm run lint`)
|
|
190
|
+
- [ ] Build successful (`npm run build`)
|
|
191
|
+
- [ ] CHANGELOG.md updated with changes
|
|
192
|
+
- [ ] Version bumped appropriately
|
|
193
|
+
- [ ] Git commit and tag created
|
|
194
|
+
- [ ] Package published successfully
|
|
195
|
+
- [ ] Git changes pushed to remote
|
|
196
|
+
- [ ] Release notes added on GitHub (optional)
|
|
197
|
+
- [ ] Team notified of new release
|
|
198
|
+
|
|
199
|
+
### Troubleshooting
|
|
200
|
+
|
|
201
|
+
**Permission Denied Error:**
|
|
202
|
+
```bash
|
|
203
|
+
npm ERR! code E403
|
|
204
|
+
npm ERR! 403 403 Forbidden - PUT https://registry.npmjs.org/@flowaccount%2fpdfmake
|
|
205
|
+
```
|
|
206
|
+
Solution: Ensure you're logged in with an account that has publish rights to `@flowaccount` organization.
|
|
207
|
+
|
|
208
|
+
**Version Already Exists:**
|
|
209
|
+
```bash
|
|
210
|
+
npm ERR! code E409
|
|
211
|
+
npm ERR! 409 Conflict - PUT https://registry.npmjs.org/@flowaccount%2fpdfmake
|
|
212
|
+
```
|
|
213
|
+
Solution: Bump the version number and try again.
|
|
214
|
+
|
|
215
|
+
**Build or Test Failures:**
|
|
216
|
+
If `publish:staging` or `publish:production` fails, the publish is automatically aborted. Fix the issues and retry.
|
|
217
|
+
|
|
218
|
+
### Version Management
|
|
219
|
+
|
|
220
|
+
Current version format: `MAJOR.MINOR.PATCH[-PRERELEASE]`
|
|
221
|
+
|
|
222
|
+
- **Production versions**: `0.2.20`, `0.2.21`, `0.3.0`
|
|
223
|
+
- **Staging versions**: `0.2.20-staging.1`, `0.2.20-staging.2`
|
|
224
|
+
- **Local versions**: `0.2.20-local.1730123456`
|
|
225
|
+
|
|
226
|
+
To check current published versions:
|
|
227
|
+
```bash
|
|
228
|
+
npm view @flowaccount/pdfmake versions
|
|
229
|
+
npm view @flowaccount/pdfmake dist-tags
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
## License
|
|
233
|
+
MIT
|
|
234
|
+
|
|
235
|
+
## Authors
|
|
236
|
+
* [@bpampuch](https://github.com/bpampuch) (founder)
|
|
237
|
+
* [@liborm85](https://github.com/liborm85)
|
|
238
|
+
|
|
239
|
+
pdfmake is based on a truly amazing library [pdfkit](https://github.com/devongovett/pdfkit) (credits to [@devongovett](https://github.com/devongovett)).
|
|
240
|
+
|
|
241
|
+
Thanks to all contributors.
|
|
242
|
+
|
|
243
|
+
---
|
|
244
|
+
|
|
245
|
+
## FlowAccount Customizations (Fork Notes)
|
|
246
|
+
|
|
247
|
+
This fork extends pdfmake 0.2.x with FlowAccount-specific features and behavior.
|
|
248
|
+
|
|
249
|
+
### 1. Remote Image URLs (Browser & Node)
|
|
250
|
+
You can now reference HTTP(S) image URLs directly in your `docDefinition.images` map or inline `image` properties.
|
|
251
|
+
|
|
252
|
+
Browser usage (helper auto-fetch):
|
|
253
|
+
```js
|
|
254
|
+
pdfMake.createPdf(docDefinition).download(); // remote image URLs resolved before layout
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
Node usage (async prefetch):
|
|
258
|
+
```js
|
|
259
|
+
const printer = new PdfPrinter(fonts);
|
|
260
|
+
await printer.resolveRemoteImages(docDefinition); // fetch & embed as data URLs
|
|
261
|
+
const pdfDoc = await printer.createPdfKitDocumentAsync(docDefinition, options);
|
|
262
|
+
pdfDoc.pipe(fs.createWriteStream('out.pdf'));
|
|
263
|
+
pdfDoc.end();
|
|
264
|
+
```
|
|
265
|
+
Errors while fetching images are swallowed (image omitted) so a bad URL will not abort PDF generation.
|
|
266
|
+
|
|
267
|
+
### 2. Dynamic Header/Footer Height Measurement
|
|
268
|
+
If your header or footer function returns variable-height content, the layout engine performs a preliminary measurement pass and adjusts `pageMargins.top` / `pageMargins.bottom` so body content starts after real header/footer height.
|
|
269
|
+
|
|
270
|
+
### 3. Vertical Alignment in Table Cells & Layers
|
|
271
|
+
Table cells and layered content can specify `verticalAlign: 'top'|'middle'|'bottom'` (same values as legacy implementation). Markers are inserted to compute and realign content after row height is known.
|
|
272
|
+
|
|
273
|
+
### 4. Layers
|
|
274
|
+
Any node can include `layers: [ nodeA, nodeB, ... ]`. Layers share the same starting Y position; the tallest layer determines consumed height. Useful for overlaying backgrounds/watermarks behind foreground text without manual positioning.
|
|
275
|
+
|
|
276
|
+
### 5. Remark Table Transformation
|
|
277
|
+
Legacy pattern: when `docStructure[2][0]` contains a `remark` table and is immediately followed by a detail node, these two nodes are transformed into added header rows inside the remark table for consistent page-break behavior.
|
|
278
|
+
|
|
279
|
+
### 6. footerBreak Logic
|
|
280
|
+
Nodes marked with `footerBreak: true` after the first such node are skipped (prevents duplicate footer sections when custom flows generate repeated fragments).
|
|
281
|
+
|
|
282
|
+
### 7. Async API Additions
|
|
283
|
+
`printer.resolveRemoteImages(docDefinition, timeoutMs?)` – fetch remote images and inline them.
|
|
284
|
+
|
|
285
|
+
`printer.createPdfKitDocumentAsync(docDefinition, options)` – async variant ensuring remote images (and any future async preprocessing) are complete before layout.
|
|
286
|
+
|
|
287
|
+
### 8. Development Helpers
|
|
288
|
+
Hot reload (playground) via `npm run dev:play` (nodemon + webpack watch) – see `dev-playground/README.md`.
|
|
289
|
+
|
|
290
|
+
### 9. Testing
|
|
291
|
+
Added unit tests covering remote image resolution and legacy layout customizations (`tests/layoutBuilder_legacy_custom.spec.js`).
|
|
292
|
+
|
|
293
|
+
### 10. Caveats
|
|
294
|
+
* Dynamic header/footer measurement is a heuristic single-pass; if header/footer height depends on total page count, final heights might differ slightly.
|
|
295
|
+
* Remote image fetching uses global `fetch`; ensure Node >= 18 or polyfill fetch in earlier runtimes.
|
|
296
|
+
|
|
297
|
+
---
|