gogap / go-wkhtmltox

A web service for wkhtmltopdf and wkhtmltoimage
Apache License 2.0
51 stars 15 forks source link

How to escape space in GlobalOptions #9

Closed nohnaimer closed 3 years ago

nohnaimer commented 3 years ago

Hi, I use https://github.com/idocking/go-wkhtmltox docker container with wkhtmltopdf 0.12.5 (with patched qt). I try to set GlobalOptions like this:

"converter": {
        "url": null,
        "extend": {
            "footer-left": "[date]",
            "footer-right": "Prepared [date] [page]/[topage]",
            "footer-font-size": "10",
            "margin-bottom": "20",
            "footer-spacing": "10"
        }
    },

I use space like in footer-right line I get error when convert to pdf:

open /tmp/go-wkhtmltox212187195/41f80aa7-be68-4437-9d43-27bb8f520780.pdf: no such file or directory

When I delete space in string line this "Prepared[date][page]/[topage]" everything work fine.

Any ideas how to escape space?

nohnaimer commented 3 years ago

I will answer to myself: Rebuild container without xvfb in alpine. Install into container wkhtmltopdf 0.12.5/6 (with patchet qt) and everything work fine.

FROM golang:1.15-alpine AS build

RUN apk add --no-cache git
RUN go get github.com/nohnaimer/go-wkhtmltox
WORKDIR $GOPATH/src/github.com/nohnaimer/go-wkhtmltox
RUN export CGO_ENABLED=0 && go build -o $GOPATH/src/github.com/nohnaimer/go-wkhtmltox

FROM surnet/alpine-wkhtmltopdf:3.13.5-0.12.6-full as wkhtmltopdf

FROM alpine:3.14

# Install needed packages
RUN apk add --update --no-cache \
        libgcc \
        libstdc++ \
        musl \
        qt5-qtbase \
        qt5-qtbase-x11 \
        qt5-qtsvg \
        qt5-qtwebkit \
        ttf-freefont \
        font-noto-kannada \
        fontconfig \
        ca-certificates

# Install wkhtmltopdf
RUN apk add --update --no-cache --repository  http://dl-cdn.alpinelinux.org/alpine/v3.14/main/ wkhtmltopdf=0.12.6-r0

# Copy pached wkhtmltopdf to system
COPY --from=wkhtmltopdf /bin/wkhtmltopdf /usr/bin/wkhtmltopdf
COPY --from=wkhtmltopdf /bin/wkhtmltoimage /usr/bin/wkhtmltoimage
COPY --from=wkhtmltopdf /lib/libwkhtmltox.* /usr/lib/

WORKDIR /app
COPY . /app

# Clean up when done
RUN rm -rf /tmp/* && \
    rm -rf /var/cache/apk/*

COPY --from=build /go/bin/go-wkhtmltox /app

VOLUME /app/templates