Skip to content

Commit e6cf03d

Browse files
authored
4.0.0
1 parent a688c8f commit e6cf03d

File tree

104 files changed

+534
-159
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+534
-159
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ yarn add jspdf
2929
Alternatively, load it from a CDN:
3030

3131
```html
32-
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/3.0.4/jspdf.umd.min.js"></script>
32+
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/4.0.0/jspdf.umd.min.js"></script>
3333
```
3434

3535
Or always get latest version via [unpkg](https://unpkg.com/browse/jspdf/)
@@ -208,7 +208,7 @@ Alternatively, you can load the prebundled polyfill file. This is not recommende
208208
loading polyfills multiple times. Might still be nifty for small applications or quick POCs.
209209

210210
```html
211-
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/3.0.4/polyfills.umd.js"></script>
211+
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/4.0.0/polyfills.umd.js"></script>
212212
```
213213

214214
## Use of Unicode Characters / UTF-8:

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jspdf",
3-
"version": "3.0.4",
3+
"version": "4.0.0",
44
"homepage": "https://github.com/parallax/jsPDF",
55
"description": "PDF Document creation from JavaScript",
66
"main": [

dist/jspdf.es.js

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/** @license
22
*
33
* jsPDF - PDF Document creation from JavaScript
4-
* Version 3.0.4 Built on 2025-11-19T12:48:37.232Z
4+
* Version 4.0.0 Built on 2025-12-18T10:27:09.425Z
55
* CommitID 00000000
66
*
77
* Copyright (c) 2010-2025 James Hall <james@parall.ax>, https://github.com/MrRio/jsPDF
@@ -5965,7 +5965,7 @@ jsPDF.API = {
59655965
* @type {string}
59665966
* @memberof jsPDF#
59675967
*/
5968-
jsPDF.version = "3.0.4";
5968+
jsPDF.version = "4.0.0";
59695969

59705970
var jsPDFAPI = jsPDF.API;
59715971
var scaleFactor = 1;
@@ -13301,7 +13301,6 @@ function parseFontFamily(input) {
1330113301
* @module
1330213302
*/
1330313303
(function (jsPDFAPI) {
13304-
1330513304
/**
1330613305
* @name loadFile
1330713306
* @function
@@ -13314,6 +13313,39 @@ function parseFontFamily(input) {
1331413313
return browserRequest(url, sync, callback);
1331513314
};
1331613315

13316+
/**
13317+
* Controls which local files may be read by jsPDF when running under Node.js.
13318+
*
13319+
* Security recommendation:
13320+
* - We strongly recommend using Node's permission flags (`node --permission --allow-fs-read=...`) instead of this property,
13321+
* especially in production. The Node flags are enforced by the runtime and provide stronger guarantees.
13322+
*
13323+
* Behavior:
13324+
* - When present, jsPDF will allow reading only if the requested, resolved absolute path matches any entry in this array.
13325+
* - Each entry can be either:
13326+
* - An absolute or relative file path for an exact match, or
13327+
* - A prefix ending with a single wildcard `*` to allow all paths starting with that prefix.
13328+
* - Examples of allowed patterns:
13329+
* - `"./fonts/MyFont.ttf"` (exact match by resolved path)
13330+
* - `"/abs/path/to/file.txt"` (exact absolute path)
13331+
* - `"./assets/*"` (any file whose resolved path starts with the resolved `./assets/` directory)
13332+
*
13333+
* Notes:
13334+
* - If Node's permission API is available (`process.permission`), it is checked first. If it denies access, reading will fail regardless of `allowFsRead`.
13335+
* - If neither `process.permission` nor `allowFsRead` is set, reading from the local file system is disabled and an error is thrown.
13336+
*
13337+
* Example:
13338+
* ```js
13339+
* const doc = jsPDF();
13340+
* doc.allowFsRead = ["./fonts/*", "./images/logo.png"]; // allow everything under ./fonts and a single file
13341+
* const ttf = doc.loadFile("./fonts/MyFont.ttf", true);
13342+
* ```
13343+
*
13344+
* @property {string[]|undefined}
13345+
* @name allowFsRead
13346+
*/
13347+
jsPDFAPI.allowFsRead = undefined;
13348+
1331713349
/**
1331813350
* @name loadImageFile
1331913351
* @function

dist/jspdf.es.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/jspdf.es.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/jspdf.es.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/jspdf.node.js

Lines changed: 79 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/** @license
22
*
33
* jsPDF - PDF Document creation from JavaScript
4-
* Version 3.0.4 Built on 2025-11-19T12:48:37.233Z
4+
* Version 4.0.0 Built on 2025-12-18T10:27:09.425Z
55
* CommitID 00000000
66
*
77
* Copyright (c) 2010-2025 James Hall <james@parall.ax>, https://github.com/MrRio/jsPDF
@@ -6902,7 +6902,7 @@ jsPDF.API = {
69026902
* @type {string}
69036903
* @memberof jsPDF#
69046904
*/
6905-
jsPDF.version = "3.0.4";
6905+
jsPDF.version = "4.0.0";
69066906

69076907
/* global jsPDF */
69086908

@@ -15891,7 +15891,6 @@ function parseFontFamily(input) {
1589115891
* @module
1589215892
*/
1589315893
(function(jsPDFAPI) {
15894-
1589515894
/**
1589615895
* @name loadFile
1589715896
* @function
@@ -15903,9 +15902,42 @@ function parseFontFamily(input) {
1590315902
jsPDFAPI.loadFile = function(url, sync, callback) {
1590415903

1590515904
// eslint-disable-next-line no-unreachable
15906-
return nodeReadFile(url, sync, callback);
15905+
return nodeReadFile.call(this, url, sync, callback);
1590715906
};
1590815907

15908+
/**
15909+
* Controls which local files may be read by jsPDF when running under Node.js.
15910+
*
15911+
* Security recommendation:
15912+
* - We strongly recommend using Node's permission flags (`node --permission --allow-fs-read=...`) instead of this property,
15913+
* especially in production. The Node flags are enforced by the runtime and provide stronger guarantees.
15914+
*
15915+
* Behavior:
15916+
* - When present, jsPDF will allow reading only if the requested, resolved absolute path matches any entry in this array.
15917+
* - Each entry can be either:
15918+
* - An absolute or relative file path for an exact match, or
15919+
* - A prefix ending with a single wildcard `*` to allow all paths starting with that prefix.
15920+
* - Examples of allowed patterns:
15921+
* - `"./fonts/MyFont.ttf"` (exact match by resolved path)
15922+
* - `"/abs/path/to/file.txt"` (exact absolute path)
15923+
* - `"./assets/*"` (any file whose resolved path starts with the resolved `./assets/` directory)
15924+
*
15925+
* Notes:
15926+
* - If Node's permission API is available (`process.permission`), it is checked first. If it denies access, reading will fail regardless of `allowFsRead`.
15927+
* - If neither `process.permission` nor `allowFsRead` is set, reading from the local file system is disabled and an error is thrown.
15928+
*
15929+
* Example:
15930+
* ```js
15931+
* const doc = jsPDF();
15932+
* doc.allowFsRead = ["./fonts/*", "./images/logo.png"]; // allow everything under ./fonts and a single file
15933+
* const ttf = doc.loadFile("./fonts/MyFont.ttf", true);
15934+
* ```
15935+
*
15936+
* @property {string[]|undefined}
15937+
* @name allowFsRead
15938+
*/
15939+
jsPDFAPI.allowFsRead = undefined;
15940+
1590915941
/**
1591015942
* @name loadImageFile
1591115943
* @function
@@ -15922,10 +15954,51 @@ function parseFontFamily(input) {
1592215954
var fs = require("fs");
1592315955
var path = require("path");
1592415956

15925-
url = path.resolve(url);
15957+
if (!process.permission && !this.allowFsRead) {
15958+
throw new Error(
15959+
"Trying to read a file from local file system. To enable this feature either run node with the --permission and --allow-fs-read flags or set the jsPDF.allowFsRead property."
15960+
);
15961+
}
15962+
15963+
try {
15964+
url = fs.realpathSync(path.resolve(url));
15965+
} catch (e) {
15966+
if (sync) {
15967+
return undefined;
15968+
} else {
15969+
callback(undefined);
15970+
return;
15971+
}
15972+
}
15973+
15974+
if (process.permission && !process.permission.has("fs.read", url)) {
15975+
throw new Error(`Cannot read file '${url}'. Permission denied.`);
15976+
}
15977+
15978+
if (this.allowFsRead) {
15979+
const allowRead = this.allowFsRead.some(allowedUrl => {
15980+
const starIndex = allowedUrl.indexOf("*");
15981+
if (starIndex >= 0) {
15982+
const fixedPart = allowedUrl.substring(0, starIndex);
15983+
let resolved = path.resolve(fixedPart);
15984+
if (fixedPart.endsWith(path.sep) && !resolved.endsWith(path.sep)) {
15985+
resolved += path.sep;
15986+
}
15987+
return url.startsWith(resolved);
15988+
} else {
15989+
return url === path.resolve(allowedUrl);
15990+
}
15991+
});
15992+
if (!allowRead) {
15993+
throw new Error(`Cannot read file '${url}'. Permission denied.`);
15994+
}
15995+
}
15996+
1592615997
if (sync) {
1592715998
try {
15928-
result = fs.readFileSync(url, { encoding: "latin1" });
15999+
result = fs.readFileSync(url, {
16000+
encoding: "latin1"
16001+
});
1592916002
} catch (e) {
1593016003
return undefined;
1593116004
}

dist/jspdf.node.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)