Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesnt work with node js wrapper? #40

Closed
c3budiman opened this issue Aug 23, 2023 · 2 comments
Closed

Doesnt work with node js wrapper? #40

c3budiman opened this issue Aug 23, 2023 · 2 comments

Comments

@c3budiman
Copy link

c3budiman commented Aug 23, 2023

hi love your works, but i kinda stressed out why it is not working on my projects.
i use this wrapper: https://www.npmjs.com/package/wkhtmltopdf
and run it in windows server 2019 environment, with docker.

minimal replication:

// tes.js
var fs = require("fs");
var wkhtmltopdf = require('wkhtmltopdf');

// URL
wkhtmltopdf('http://google.com/', { pageSize: 'letter' })
  .pipe(fs.createWriteStream('out.pdf'));

my dockerfile:

FROM surnet/alpine-node-wkhtmltopdf:16.18.0-0.12.6-full AS deps

ADD package.json /tmp/package.json
RUN cd /tmp && npm install
RUN mkdir -p /app && cp -a /tmp/node_modules /app/

# Set work directory
WORKDIR /app
COPY . /app

RUN npx prisma generate
# RUN npm run swagger
# RUN npm run build

COPY ./templates /app/dist/templates

# Set the command to run your app
CMD ["npm", "run", "dev"]

my compose:

version: "3.1"

services:
  backend:
    build: "./"
    image: ppic-pil:latest
    container_name: api-ppic
    hostname: apippic
    command: sh -c "env | grep -E '^[A-Za-z_]+=' > .env && npm run dev"
    volumes:
      - "./photo:/app/photo"
      - "./pdf:/app/pdf"
      - "./signature:/app/signature"
    ports:
      - target: 9334
        published: 9334
        protocol: tcp
    env_file:
      - ./.env
    restart: always

but it return weird error and no way i could possibly know why? when i run node test.js or my project function. it is working well on native machine running ubuntu, mac, and windows but cant work properly on docker running alpine and debian. any ideas?

image

@chdanielmueller
Copy link
Member

chdanielmueller commented Aug 23, 2023

Hi @c3budiman

Please try to run wkhtmltopdf with debug mode wkhtmltopdf('http://google.com/', { pageSize: 'letter', debug: true }) which should get you more information about what commands will be executed and which one fails.
Please also check that /bin/bash is available on your container.
Also try to write the file in another directory fs.createWriteStream('/tmp/out.pdf') to make sure that you have proper write permissions with your user.

I hope I was able to assist your troubleshooting

@c3budiman
Copy link
Author

okay i figured out, that it need bash to work with.

so adding :

RUN apk update && apk upgrade && apk add bash

solve the problem. thankss
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants