Skip to content

Commit 04eb54b

Browse files
committed
chore: Updated deps
1 parent 635ddf4 commit 04eb54b

File tree

3 files changed

+123
-15
lines changed

3 files changed

+123
-15
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"test": "jest --passWithNoTests"
3838
},
3939
"dependencies": {
40-
"@napi-rs/canvas": "^0.1.66",
40+
"@napi-rs/canvas": "0.1.65",
4141
"node-addon-api": "^8.3.0",
4242
"node-gyp": "^11.0.0",
4343
"pdfjs-dist": "4.10.38"

src/pdf-to-png.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,23 @@
33
*/
44
import { readFileSync } from 'node:fs'
55
import { dirname, join } from 'node:path'
6-
import { getDocument } from 'pdfjs-dist'
6+
import { getDocument } from 'pdfjs-dist/legacy/build/pdf.mjs'
77

8-
const PDFJS_DIR = dirname(require.resolve('pdfjs-dist'))
9-
const C_MAP_URL = join(PDFJS_DIR, '../cmaps/')
10-
11-
// Where the standard fonts are located.
12-
const STANDARD_FONT_DATA_URL = join(PDFJS_DIR, '../standard_fonts/')
8+
const PDFJS_DIR = join(dirname(require.resolve('pdfjs-dist')), '..')
139

1410
export async function pdfToPng(
1511
pdf: string | Buffer
1612
): Promise<Buffer[]> {
13+
1714
// Load PDF
1815
const data = new Uint8Array(Buffer.isBuffer(pdf) ? pdf : readFileSync(pdf))
1916
const loadingTask = getDocument({
2017
data,
21-
cMapUrl: C_MAP_URL,
22-
cMapPacked: true,
23-
standardFontDataUrl: STANDARD_FONT_DATA_URL
18+
// Where the standard fonts are located.
19+
standardFontDataUrl: join(PDFJS_DIR, 'standard_fonts/'),
20+
// Some PDFs need external cmaps.
21+
cMapUrl: join(PDFJS_DIR, 'cmaps/'),
22+
cMapPacked: true
2423
})
2524

2625
const pdfDocument = await loadingTask.promise
@@ -30,19 +29,19 @@ export async function pdfToPng(
3029
const images: Buffer[] = []
3130
for (let page = 1; page <= numPages; page += 1) {
3231
const pdfPage = await pdfDocument.getPage(page)
32+
const canvasFactory = pdfDocument.canvasFactory
3333

3434
const viewport = pdfPage.getViewport({ scale: 1.0 })
3535
// @ts-expect-error unknown method on Object
36-
const canvasAndContext = pdfDocument.canvasFactory.create(viewport.width, viewport.height)
36+
const canvasAndContext = canvasFactory.create(viewport.width, viewport.height)
3737

3838
await pdfPage.render({
3939
canvasContext: canvasAndContext.context,
4040
viewport
4141
}).promise
4242

43+
images.push(canvasAndContext.canvas.toBuffer('image/png'))
4344
pdfPage.cleanup()
44-
45-
images.push(canvasAndContext.toBuffer('image/png'))
4645
}
4746

4847
return images

yarn.lock

Lines changed: 111 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -797,77 +797,186 @@ __metadata:
797797
languageName: node
798798
linkType: hard
799799

800+
"@napi-rs/canvas-android-arm64@npm:0.1.65":
801+
version: 0.1.65
802+
resolution: "@napi-rs/canvas-android-arm64@npm:0.1.65"
803+
conditions: os=android & cpu=arm64
804+
languageName: node
805+
linkType: hard
806+
800807
"@napi-rs/canvas-android-arm64@npm:0.1.66":
801808
version: 0.1.66
802809
resolution: "@napi-rs/canvas-android-arm64@npm:0.1.66"
803810
conditions: os=android & cpu=arm64
804811
languageName: node
805812
linkType: hard
806813

814+
"@napi-rs/canvas-darwin-arm64@npm:0.1.65":
815+
version: 0.1.65
816+
resolution: "@napi-rs/canvas-darwin-arm64@npm:0.1.65"
817+
conditions: os=darwin & cpu=arm64
818+
languageName: node
819+
linkType: hard
820+
807821
"@napi-rs/canvas-darwin-arm64@npm:0.1.66":
808822
version: 0.1.66
809823
resolution: "@napi-rs/canvas-darwin-arm64@npm:0.1.66"
810824
conditions: os=darwin & cpu=arm64
811825
languageName: node
812826
linkType: hard
813827

828+
"@napi-rs/canvas-darwin-x64@npm:0.1.65":
829+
version: 0.1.65
830+
resolution: "@napi-rs/canvas-darwin-x64@npm:0.1.65"
831+
conditions: os=darwin & cpu=x64
832+
languageName: node
833+
linkType: hard
834+
814835
"@napi-rs/canvas-darwin-x64@npm:0.1.66":
815836
version: 0.1.66
816837
resolution: "@napi-rs/canvas-darwin-x64@npm:0.1.66"
817838
conditions: os=darwin & cpu=x64
818839
languageName: node
819840
linkType: hard
820841

842+
"@napi-rs/canvas-linux-arm-gnueabihf@npm:0.1.65":
843+
version: 0.1.65
844+
resolution: "@napi-rs/canvas-linux-arm-gnueabihf@npm:0.1.65"
845+
conditions: os=linux & cpu=arm
846+
languageName: node
847+
linkType: hard
848+
821849
"@napi-rs/canvas-linux-arm-gnueabihf@npm:0.1.66":
822850
version: 0.1.66
823851
resolution: "@napi-rs/canvas-linux-arm-gnueabihf@npm:0.1.66"
824852
conditions: os=linux & cpu=arm
825853
languageName: node
826854
linkType: hard
827855

856+
"@napi-rs/canvas-linux-arm64-gnu@npm:0.1.65":
857+
version: 0.1.65
858+
resolution: "@napi-rs/canvas-linux-arm64-gnu@npm:0.1.65"
859+
conditions: os=linux & cpu=arm64 & libc=glibc
860+
languageName: node
861+
linkType: hard
862+
828863
"@napi-rs/canvas-linux-arm64-gnu@npm:0.1.66":
829864
version: 0.1.66
830865
resolution: "@napi-rs/canvas-linux-arm64-gnu@npm:0.1.66"
831866
conditions: os=linux & cpu=arm64 & libc=glibc
832867
languageName: node
833868
linkType: hard
834869

870+
"@napi-rs/canvas-linux-arm64-musl@npm:0.1.65":
871+
version: 0.1.65
872+
resolution: "@napi-rs/canvas-linux-arm64-musl@npm:0.1.65"
873+
conditions: os=linux & cpu=arm64 & libc=musl
874+
languageName: node
875+
linkType: hard
876+
835877
"@napi-rs/canvas-linux-arm64-musl@npm:0.1.66":
836878
version: 0.1.66
837879
resolution: "@napi-rs/canvas-linux-arm64-musl@npm:0.1.66"
838880
conditions: os=linux & cpu=arm64 & libc=musl
839881
languageName: node
840882
linkType: hard
841883

884+
"@napi-rs/canvas-linux-riscv64-gnu@npm:0.1.65":
885+
version: 0.1.65
886+
resolution: "@napi-rs/canvas-linux-riscv64-gnu@npm:0.1.65"
887+
conditions: os=linux & cpu=riscv64 & libc=glibc
888+
languageName: node
889+
linkType: hard
890+
842891
"@napi-rs/canvas-linux-riscv64-gnu@npm:0.1.66":
843892
version: 0.1.66
844893
resolution: "@napi-rs/canvas-linux-riscv64-gnu@npm:0.1.66"
845894
conditions: os=linux & cpu=riscv64 & libc=glibc
846895
languageName: node
847896
linkType: hard
848897

898+
"@napi-rs/canvas-linux-x64-gnu@npm:0.1.65":
899+
version: 0.1.65
900+
resolution: "@napi-rs/canvas-linux-x64-gnu@npm:0.1.65"
901+
conditions: os=linux & cpu=x64 & libc=glibc
902+
languageName: node
903+
linkType: hard
904+
849905
"@napi-rs/canvas-linux-x64-gnu@npm:0.1.66":
850906
version: 0.1.66
851907
resolution: "@napi-rs/canvas-linux-x64-gnu@npm:0.1.66"
852908
conditions: os=linux & cpu=x64 & libc=glibc
853909
languageName: node
854910
linkType: hard
855911

912+
"@napi-rs/canvas-linux-x64-musl@npm:0.1.65":
913+
version: 0.1.65
914+
resolution: "@napi-rs/canvas-linux-x64-musl@npm:0.1.65"
915+
conditions: os=linux & cpu=x64 & libc=musl
916+
languageName: node
917+
linkType: hard
918+
856919
"@napi-rs/canvas-linux-x64-musl@npm:0.1.66":
857920
version: 0.1.66
858921
resolution: "@napi-rs/canvas-linux-x64-musl@npm:0.1.66"
859922
conditions: os=linux & cpu=x64 & libc=musl
860923
languageName: node
861924
linkType: hard
862925

926+
"@napi-rs/canvas-win32-x64-msvc@npm:0.1.65":
927+
version: 0.1.65
928+
resolution: "@napi-rs/canvas-win32-x64-msvc@npm:0.1.65"
929+
conditions: os=win32 & cpu=x64
930+
languageName: node
931+
linkType: hard
932+
863933
"@napi-rs/canvas-win32-x64-msvc@npm:0.1.66":
864934
version: 0.1.66
865935
resolution: "@napi-rs/canvas-win32-x64-msvc@npm:0.1.66"
866936
conditions: os=win32 & cpu=x64
867937
languageName: node
868938
linkType: hard
869939

870-
"@napi-rs/canvas@npm:^0.1.65, @napi-rs/canvas@npm:^0.1.66":
940+
"@napi-rs/canvas@npm:0.1.65":
941+
version: 0.1.65
942+
resolution: "@napi-rs/canvas@npm:0.1.65"
943+
dependencies:
944+
"@napi-rs/canvas-android-arm64": "npm:0.1.65"
945+
"@napi-rs/canvas-darwin-arm64": "npm:0.1.65"
946+
"@napi-rs/canvas-darwin-x64": "npm:0.1.65"
947+
"@napi-rs/canvas-linux-arm-gnueabihf": "npm:0.1.65"
948+
"@napi-rs/canvas-linux-arm64-gnu": "npm:0.1.65"
949+
"@napi-rs/canvas-linux-arm64-musl": "npm:0.1.65"
950+
"@napi-rs/canvas-linux-riscv64-gnu": "npm:0.1.65"
951+
"@napi-rs/canvas-linux-x64-gnu": "npm:0.1.65"
952+
"@napi-rs/canvas-linux-x64-musl": "npm:0.1.65"
953+
"@napi-rs/canvas-win32-x64-msvc": "npm:0.1.65"
954+
dependenciesMeta:
955+
"@napi-rs/canvas-android-arm64":
956+
optional: true
957+
"@napi-rs/canvas-darwin-arm64":
958+
optional: true
959+
"@napi-rs/canvas-darwin-x64":
960+
optional: true
961+
"@napi-rs/canvas-linux-arm-gnueabihf":
962+
optional: true
963+
"@napi-rs/canvas-linux-arm64-gnu":
964+
optional: true
965+
"@napi-rs/canvas-linux-arm64-musl":
966+
optional: true
967+
"@napi-rs/canvas-linux-riscv64-gnu":
968+
optional: true
969+
"@napi-rs/canvas-linux-x64-gnu":
970+
optional: true
971+
"@napi-rs/canvas-linux-x64-musl":
972+
optional: true
973+
"@napi-rs/canvas-win32-x64-msvc":
974+
optional: true
975+
checksum: 10c0/87e92baf5b4bf479c3d4f0c853f974411d62b05f772f2b5f7f0e94f7bfb3103497913ce1b9e7a176f6e8017ebfad80acc78e4d476589d0a44eac3ee6db5c81a2
976+
languageName: node
977+
linkType: hard
978+
979+
"@napi-rs/canvas@npm:^0.1.65":
871980
version: 0.1.66
872981
resolution: "@napi-rs/canvas@npm:0.1.66"
873982
dependencies:
@@ -6102,7 +6211,7 @@ __metadata:
61026211
resolution: "to-match-pdf-snapshot@workspace:."
61036212
dependencies:
61046213
"@jest/globals": "npm:^29.7.0"
6105-
"@napi-rs/canvas": "npm:^0.1.66"
6214+
"@napi-rs/canvas": "npm:0.1.65"
61066215
"@playwright/test": "npm:^1.43.0"
61076216
"@types/jest": "npm:^29.5.12"
61086217
"@types/node": "npm:^22.13.0"

0 commit comments

Comments
 (0)