From d0949f32f70d8fa86831c3d1ddf275251b88e17f Mon Sep 17 00:00:00 2001 From: "Libor M." Date: Tue, 5 Nov 2024 13:54:50 +0100 Subject: [PATCH 1/7] fix stop code after reject fetch url --- src/URLResolver.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/URLResolver.js b/src/URLResolver.js index 117bef72f..7a16387d1 100644 --- a/src/URLResolver.js +++ b/src/URLResolver.js @@ -22,6 +22,7 @@ const fetchUrl = (url, headers = {}) => { const ok = res.statusCode >= 200 && res.statusCode < 300; if (!ok) { reject(new TypeError(`Failed to fetch (status code: ${res.statusCode}, url: "${url}")`)); + return; } const chunks = []; From 2afe4c7485867aab9bc37797fa6f5c8f16e9a490 Mon Sep 17 00:00:00 2001 From: "Libor M." Date: Tue, 5 Nov 2024 13:57:25 +0100 Subject: [PATCH 2/7] consume memory in response stream after fetch url (error or redirect) --- src/URLResolver.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/URLResolver.js b/src/URLResolver.js index 7a16387d1..f8f29e22e 100644 --- a/src/URLResolver.js +++ b/src/URLResolver.js @@ -11,6 +11,8 @@ const fetchUrl = (url, headers = {}) => { h.get(url, options, res => { if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) { // redirect url + res.resume(); + fetchUrl(res.headers.location).then(buffer => { resolve(buffer); }, result => { @@ -22,6 +24,7 @@ const fetchUrl = (url, headers = {}) => { const ok = res.statusCode >= 200 && res.statusCode < 300; if (!ok) { reject(new TypeError(`Failed to fetch (status code: ${res.statusCode}, url: "${url}")`)); + res.resume(); return; } From aabcfbb8f306444dcedd1b118ae6f3daf8869af7 Mon Sep 17 00:00:00 2001 From: "Libor M." Date: Tue, 5 Nov 2024 14:02:32 +0100 Subject: [PATCH 3/7] Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 160aaccb9..246d889c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Unreleased + +- Fixed speed in Node.js if is fetching URL for image or font redirected + ## 0.3.0-beta.12 - 2024-11-03 - Added support PDF/A and PDF/UA (see [documentation](https://pdfmake.github.io/docs/0.3/document-definition-object/pdfa/)) From 41f9dde5de73e41286272054d92d4437f131a1a1 Mon Sep 17 00:00:00 2001 From: "Libor M." Date: Wed, 6 Nov 2024 12:26:47 +0100 Subject: [PATCH 4/7] nodejs 22.x LTS --- .github/workflows/node.js.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 07c239b04..1c6bccffd 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -14,7 +14,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest] - node-version: [18.x, 20.x] + node-version: [18.x, 20.x, 22.x] steps: - uses: actions/checkout@v2 From be1bf25fdc0cb6c77d40d661592dd6ee21d45dab Mon Sep 17 00:00:00 2001 From: "Libor M." Date: Wed, 6 Nov 2024 15:57:26 +0100 Subject: [PATCH 5/7] fixed aspect ratio for image with exif orientation tag #2316 --- CHANGELOG.md | 1 + src/DocMeasure.js | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 246d889c9..77b5953e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased - Fixed speed in Node.js if is fetching URL for image or font redirected +- Fixed aspect ratio for image with exif orientation tag ## 0.3.0-beta.12 - 2024-11-03 diff --git a/src/DocMeasure.js b/src/DocMeasure.js index 189c2256e..69613b015 100644 --- a/src/DocMeasure.js +++ b/src/DocMeasure.js @@ -128,8 +128,16 @@ class DocMeasure { this.convertIfBase64Image(node); let image = this.pdfDocument.provideImage(node.image); + let imageSize = { width: image.width, height: image.height }; + if (image.constructor.name === 'JPEG') { + // If EXIF orientation calls for it, swap width and height + if (image.orientation > 4) { + imageSize = { width: image.height, height: image.width }; + } + } + this.measureImageWithDimensions(node, imageSize); return node; From 1a62230877cccb717e781d78129f31aa23d23334 Mon Sep 17 00:00:00 2001 From: "Libor M." Date: Fri, 8 Nov 2024 12:52:19 +0100 Subject: [PATCH 6/7] ignore eslint.config.mjs --- .npmignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.npmignore b/.npmignore index 2304e5776..5cf1f39ec 100644 --- a/.npmignore +++ b/.npmignore @@ -9,7 +9,7 @@ yarn.lock composer.json bower.json .editorconfig -.eslintrc.json +eslint.config.mjs build-fonts.js build-examples.js babel.config.json From 39fb7dcc282c08a7e3f5932a50a7c09a1ed23e75 Mon Sep 17 00:00:00 2001 From: "Libor M." Date: Fri, 8 Nov 2024 12:54:10 +0100 Subject: [PATCH 7/7] Update .npmignore --- .npmignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.npmignore b/.npmignore index 5cf1f39ec..bd932a238 100644 --- a/.npmignore +++ b/.npmignore @@ -1,4 +1,5 @@ .git* +.idea/ dev-playground/ docs/ examples/