pdfjs-serverless
pdfjs-serverless copied to clipboard
Canvas support for serverless environments
Great lib!
Based on https://github.com/johannschopplich/pdfjs-serverless/blob/main/src/mock/canvas.mjs I assume there's currently no intent to support canvas with this lib (ie. to render a PDF page to the canvas in order to export as PNG). I tried to use https://deno.land/x/[email protected] to accomplish this, but hit multiple issues with that implementation where it's missing various Canvas APIs that PDF.js needs.
node-canvas seems to support the spec better, but as of now that library is implemented only as a native Node module (vs. WASM), so won't work in Deno Deploy (or CF Workers).
Just wanted to reach out in the odd chance you had any thoughts on this or any previous attempts to make this happen. Cheers!
Hi @gregnr!
Thanks for the flowers. And also for your interest in this library! I haven't found a pure WASM solution yet. I remember some libraries with that goal, but without full canvas support. I tried briefly, but not in depth.
If you find a library in the wild, even now or later, feel free to share it. It would be great to somehow transform PDF.js with full image rendering support for workers.
I also maintain unpdf, which inherits the work of this library. Once we have canvas support, you will be able to use renderPageAsImage for Cf workers and Deno Deploy.
This method supports passing a canvas-compatible library as an argument, which might work in your Deno situation.
Hopefully we'll figure it out one day!
Can it get an image data file inside of a pdf - export it as base 64 https://stackoverflow.com/questions/18680261/extract-images-from-pdf-file-with-javascript This is needed to do pdf-to-html in cloudflare workers, and to keep images common in academic pdfs to show them to user later
possible for rendering canvas https://github.com/renderlet/wander
How about @napi-rs/canvas
How about @napi-rs/canvas
https://github.com/Brooooooklyn/canvas/blob/main/example/image-data.js This might work as polyfil.
I'm using this pdf npm to build airesearch.js.org and qwksearch alt to google that shows pdf text alongside result list. Very much need to include the images in a pdf as well, which can be exported as base64 example: https://qwksearch.com/?q=attention+is+all+you+need+pdf