File tree Expand file tree Collapse file tree 3 files changed +9
-300
lines changed Expand file tree Collapse file tree 3 files changed +9
-300
lines changed Original file line number Diff line number Diff line change 3737 "test" : " jest --passWithNoTests"
3838 },
3939 "dependencies" : {
40- "canvas" : " ^3 .1.0 " ,
40+ "@napi-rs/ canvas" : " ^0 .1.66 " ,
4141 "node-addon-api" : " ^8.3.0" ,
4242 "node-gyp" : " ^11.0.0" ,
4343 "pdfjs-dist" : " 4.10.38"
Original file line number Diff line number Diff line change 11/**
22 * https://github.com/mozilla/pdf.js/blob/3b94e9fdce616a9b4899800559cbca15169acca6/examples/node/pdf2png/pdf2png.mjs
33 */
4- import * as Canvas from 'canvas'
54import { readFileSync } from 'node:fs'
65import { dirname , join } from 'node:path'
76import { getDocument } from 'pdfjs-dist'
@@ -33,10 +32,11 @@ export async function pdfToPng(
3332 const pdfPage = await pdfDocument . getPage ( page )
3433
3534 const viewport = pdfPage . getViewport ( { scale : 1.0 } )
36- const canvasAndContext = Canvas . createCanvas ( viewport . width , viewport . height )
35+ // @ts -expect-error unknown method on Object
36+ const canvasAndContext = pdfDocument . canvasFactory . create ( viewport . width , viewport . height )
3737
3838 await pdfPage . render ( {
39- canvasContext : canvasAndContext . getContext ( '2d' ) as never ,
39+ canvasContext : canvasAndContext . context ,
4040 viewport
4141 } ) . promise
4242
You can’t perform that action at this time.
0 commit comments