I’ve been trying to convert PDF files to images using various methods and packages in Node.js. While the code works fine locally, it fails when deployed to Google Cloud Functions. I want to convert a pdf into images. Each page of pdf must be converted into an image.
I am using Node.js 20 and Mac M1.
I have used many npm packages like pdf2pic, pdf2image, pdf-lib, canvas, gm etc. Here are the details:
pdf-image: Works locally fine but fails on Google Cloud Functions
gm (GraphicsMagick): Code works locally but fails on Google Cloud Functions with error: Command failed: convert-im6.q16: not authorized …
pdf2pic: Works locally but fails on Google Cloud Functions with error
pdf-lib: Attempted to use PDFDocument and renderToBuffer, but these methods are not suitable for rendering pages as images
canvas: Required for some PDF rendering libraries, but it’s not supported in my environment
pdf-poppler: Tried using pdf-poppler for conversion. Faced issues with deploying the compiled binaries required for pdf-poppler
Of all these packages, i found pdf-image easy to use and perfect for my use case but it fails on gcp.