2

When i generate a PDF from HTML file using html-pdf node module, it is throwing following error (only in docker). Same code is working in local machine ubuntu 18.04

 write EPIPE\n    at afterWriteDispatched (internal/stream_base_commons.js:154:25)\n    at writeGeneric (internal/stream_base_commons.js:145:3)\n    at Socket._writeGeneric (net.js:784:11)\n    at Socket._write (net.js:796:8)\n    at doWrite (_stream_writable.js:403:12)\n    at writeOrBuffer (_stream_writable.js:387:5)\n    at Socket.Writable.write (_stream_writable.js:318:11)\n    at PDF.PdfExec [as exec] (/usr/src/app/node_modules/html-pdf/lib/pdf.js:141:15)\n    at PDF.PdfToFile [as toFile] (/usr/src/app/node_modules/html-pdf/lib/pdf.js:83:8)\n  

Phantom Error:

 spawn /usr/src/app/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs ENOENT\n    at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19)\n  
Dinesh
  • 426
  • 5
  • 15

1 Answers1

0

html-pdf use a npm package phantomjs-prebuilt

phantomjs-prebuilt will automatically install phantomjs for you based on your OS/Archritecture

It's important that the node_modules doesn't get copied over to the docker image And rather get installed on the docker file itself

I'm busy testing a custom docker image for azure, so you can use a different base image

Following the this thread you would need to install a couple of dependencies as well https://gist.github.com/julionc/7476620

Ensure you have node_modules/ in your .dockerignore file

mode_modules/

Docker file for azure functions. For apline you would use apk add instead of apt-get install

FROM mcr.microsoft.com/azure-functions/node:3.0-node12-appservice

RUN apt-get update
RUN apt-get install build-essential chrpath libssl-dev libxft-dev -y
RUN apt-get install libfreetype6 libfreetype6-dev -y
RUN apt-get install libfontconfig1 libfontconfig1-dev -y

ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
    AzureFunctionsJobHost__Logging__Console__IsEnabled=true \
    OPENSSL_CONF=/etc/ssl/

COPY . /home/site/wwwroot


RUN cd /home/site/wwwroot && \
    npm install

Including OPENSSL_CONF=/etc/ssl/ as an environment Found the solution here