Reputation: 2818
I'm having trouble making the PDF.js library render a PDF to a PNG file.
My steps are :
mkdir pdf-test
npm init
npm install pdfjs-dist assert canvas
pdf2png.js
from the examples page to the working folderpdf2png.js
on line 54node pdf2png.js
I'm getting the following output:
# PDF document loaded.
(node:13760) UnhandledPromiseRejectionWarning: AssertionError [ERR_ASSERTION]: Invalid canvas size
at NodeCanvasFactory_create [as create] (D:\tests\pdf-test\pdf2png.js:23:5)
at D:\tests\pdf-test\pdf2png.js:70:21
Surprisingly, if I clone the entire PDF.js repository and follow the instructions to build it from source, the script work fine and I get a correctly rendered PNG file.
What am I missing when installing a prebuilt version from NPM?
Upvotes: 1
Views: 1126
Reputation: 11809
You are missing an update.
The latest pdfjs-dist
npm version is v2.0.943
from Oct 27, 2018
, while the latest GitHub release is v2.1.266
from Feb 16, 2019
.
This latest update has this changelog: migrate to canvas 2.x api which also affected pdf2png.js
file, as you can see here:
So if you used the latest pdf2png.js
file from pdf.js
GitHub repository, you had some kind of version mismatch between the pdfjs-dist
npm package and the pdf2png.js
file.
Upvotes: 1