mrafiqk / html-pdf-node

187 stars 119 forks source link

Can not create PDF while building with Docker #43

Closed ghoshpushpendu closed 2 years ago

ghoshpushpendu commented 2 years ago

The PDF is getting generated while running the server on local machine.

But when deploying to docker ( ecs Fargate ) it can not create PDF with error Error: Failed to launch the browser process!

ismanf commented 2 years ago

same here, seems it needs some manual work to extract chromium bin

ghoshpushpendu commented 2 years ago

https://stackoverflow.com/a/62383642/10098625

Follow this link. This ll help. The thing is install headless chrome on your docker. And this link above will guide you to that.

DuiLego commented 2 years ago

This works for me:

AWS- EC2 Amazon Linux Node JS

https://developers.google.com/web/tools/puppeteer/troubleshooting?hl=pl#running_puppeteer_on_aws_ec2_instance_running_amazon-linux

aashishPrasad-crubn commented 1 year ago

Let me save you all complex configs.

Just add these 2 lines in Dockerfile.

RUN apt-get update && \
    apt-get install -y fonts-liberation gconf-service libappindicator1 libasound2 libatk1.0-0 libcairo2 libcups2 libfontconfig1 libgbm-dev libgdk-pixbuf2.0-0 libgtk-3-0 libicu-dev libjpeg-dev libnspr4 libnss3 libpango-1.0-0 libpangocairo-1.0-0 libpng-dev libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 xdg-utils
RUN chmod -R o+rwx node_modules/puppeteer/.local-chromium

And put this line inside the node_modules/html-pdf-node/index.js

 const browser = await puppeteer.launch({
    headless: true,
    args: [
        "--disable-gpu",
        "--disable-dev-shm-usage",
        "--disable-setuid-sandbox",
        "--no-sandbox",
    ]
  });