Context: PDF to Image Conversion for Google Cloud Vision (NestJS API)

marcocrepaldiHOBBY

16 days ago

We are currently working on a NestJS backend API that handles file uploads for insurance proposal documents. The goal is to automatically extract text content from PDF and image files using Google Cloud Vision.

To achieve this, we are:

  1. Accepting PDF or image uploads from the frontend

  2. If a PDF is uploaded, we convert it to PNG using the pdf2pic library

  3. Once converted to an image, we send it to Google Cloud Vision for OCR processing

  4. The extracted text is saved as part of a new InsuranceProposal entity

This solution works perfectly in development and locally on our machines.

Problem on Railway deployment

Apr 09 14:43:08

eca158fe

Apr 09 14:43:08

eca158fe

[Upload] Verificando tipo de arquivo...

Apr 09 14:43:08

eca158fe

[Upload] É um PDF. Iniciando conversão...

Apr 09 14:43:08

eca158fe

[Upload] Erro ao converter PDF para imagem: Error: Could not execute GraphicsMagick/ImageMagick: gm "convert" "-density" "300x300" "-quality" "75" "-[0]" "-resize" "768x512!" "-compress" "jpeg" "/app/uploads/temp/page-ba24e955-312b-4bbe-83de-a96f7f71d9bb.1.png" this most likely means the gm/convert binaries can't be found

Apr 09 14:43:08

eca158fe

at ChildProcess.<anonymous> (/app/node_modules/gm/lib/command.js:249:12)

Apr 09 14:43:08

eca158fe

at ChildProcess.emit (node:events:518:28)

Apr 09 14:43:08

eca158fe

at ChildProcess._handle.onexit (node:internal/child_process:291:12)

does not have the native system binaries required for PDF to image conversion with pdf2pic.

0 Replies