adrg / go-wkhtmltopdf

Handcrafted Go bindings for wkhtmltopdf and high-level HTML to PDF conversion interface
https://pkg.go.dev/github.com/adrg/go-wkhtmltopdf
MIT License
236 stars 21 forks source link

how let go-wkhtmltopdf know where is wkhtmltox/pdf.h #35

Open rdhmuhammad opened 1 year ago

rdhmuhammad commented 1 year ago

hi man, sorry i dont where else to ask this, the repo where i used the wkhtmltopdf image not responding the issue.

So, i try to use wkhtmltopdf on my dockerfile which look like this

FROM ghcr.io/surnet/alpine-wkhtmltopdf:3.17.0-0.12.6-small as wkhtmltopdf
FROM golang:1.19.9-alpine3.17

# Install dependencies for wkhtmltopdf
RUN apk add --no-cache \
    libstdc++ libx11  libxrender  libxext libssl1.1 
    ca-certificates fontconfig freetype ttf-dejavu \
    ttf-droid ttf-freefont ttf-liberation \
    # more fonts
  && apk add --no-cache --virtual .build-deps \
    msttcorefonts-installer \
  # Install microsoft fonts
  && update-ms-fonts \
  && fc-cache -f \
  # Clean up when done
  && rm -rf /tmp/* \
  && apk del .build-deps \

COPY --from=wkhtmltopdf /bin/wkhtmltopdf /bin/wkhtmltopdf
COPY --from=wkhtmltopdf /bin/libwkhtmltox* /bin/

WORKDIR /src
COPY . .
RUN go mod vendor && go mod verify
RUN go build -o main .

EXPOSE 8080

CMD ["./main"]

which totally fine when i havent install https://github.com/adrg/go-wkhtmltopdf but when i install it and build again. its always throws this error error during docker build.

> [builder 7/7] RUN go build -o /app-bin /src/main.go:
#0 3.510 # github.com/adrg/go-wkhtmltopdf
#0 3.510 vendor/github.com/adrg/go-wkhtmltopdf/converter.go:7:10: fatal error: wkhtmltox/pdf.h: No such file or directory
#0 3.510     7 | #include <wkhtmltox/pdf.h>
#0 3.510       |          ^~~~~~~~~~~~~~~~~
#0 3.510 compilation terminated

do you know how to let the go compiler where the wkhtmltox is ? i've stry specify cgo flags but still doesnt work

i really appreciate your answer,

mateusfmello commented 1 year ago

I have the same problem

mateusfmello commented 1 year ago

The solution I found was this:

Links:

  1. https://github.com/adrg/go-wkhtmltopdf/wiki/Install-on-Linux
  2. https://wkhtmltopdf.org/downloads.html

In this case it was simple, all that was missing was to install "wkhtmltox", I followed the documentation and it worked perfectly.

sudo apt-get install xfonts-75dpi

Download the corresponding file that is available at link 2

sudo dpkg -i wkhtmltox.deb

Remember to change "wkhtmltox.deb" to the full path to the previously downloaded package file

sudo ldconfig

After that I ran my system and it worked perfectly, the result is amazing, congratulations to everyone working on this project