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

page.FooterRight.Set("[page]") from example not working #76

Open
casjonker opened this issue Dec 2, 2021 · 10 comments
Open

page.FooterRight.Set("[page]") from example not working #76

casjonker opened this issue Dec 2, 2021 · 10 comments

Comments

@casjonker
Copy link

Hiya, following your example I can't seem to get a footer or header in...

OS: "Debian GNU/Linux 10 (buster)"

"My" code:

pdfg, err := wk.NewPDFGenerator()
if err != nil {
    return nil, err
}
page := wk.NewPage("https://godoc.org/github.com/SebastiaanKlippert/go-wkhtmltopdf")

page.FooterRight.Set("[page]")
page.FooterFontSize.Set(10)
page.Zoom.Set(0.95)

pdfg.AddPage(page)
err = pdfg.Create()
if err != nil {
    return nil, err
}

return pdfg.Bytes(), err

Any idea or tips of what I'm doing wrong here? Is it the .Bytes() ?

@SebastiaanKlippert
Copy link
Owner

Your code is correct. The Bytes() will not be the issue, that just returns the buffer.

I created a test with your code on https://github.com/SebastiaanKlippert/go-wkhtmltopdf/blob/issue/76/wkhtmltopdf_test.go#L257

On both Windows and Ubuntu this works as intended.
afbeelding

You can download the artifacts at https://github.com/SebastiaanKlippert/go-wkhtmltopdf/suites/4538274705/artifacts/121644975

Can you share your result? I could run a Github action in Debian buster if you want, but since the Go code is correct any difference in OS will probably not be in my code but rather wkhtmltopdf itself.

@maeglindeveloper
Copy link

Hey @SebastiaanKlippert ,
I also have this issue unfortunetely.
Do we need to set some margin or something else to have it worked ?

@SebastiaanKlippert
Copy link
Owner

No, it should work as shown in the test I created above.
Unfortunatley I have never been able to reproduce this so if you can share some more info on OS and wkhtmltopdf versions that would be great.
But I do doubt that is an issue in my Go wrapper, more likely it is a wkhtmltopdf issue, so please try it manually first to test this.
Since https://github.com/wkhtmltopdf/wkhtmltopdf is no longer maintained I don't know if it will ever be addressed,

@maeglindeveloper
Copy link

Linux (fedora)
wkhtmltopdf 0.12.6
go-wkhtmltopdf 1.7.2

@maeglindeveloper
Copy link

@SebastiaanKlippert related issue there as well #50
I used the test code straighforward with the versions I shared above :/

@SebastiaanKlippert
Copy link
Owner

SebastiaanKlippert commented Feb 2, 2022

In the related issue the original reporter only said "Ok thank you. Its working" without providing any more details.
So I assume that he tried my suggested method with reading the files from disk and not from stdin.

So that means that in wkhtmltopdf this works wkhtmltopdf 'body.html' --header-html 'header.html' --footer-html 'footer.html' 'test.pdf' but it breaks (on your OS) when using stdin.

Then the only workaround is to use the code I provided in the related issue, but then you would have to write the HTML input files to disk first.

It does not look like something I can solve in the Go wrapper as it is an issue in wkhtmltopdf itself (wkhtmltopdf/wkhtmltopdf#3014)

@mvisonneau
Copy link

FWIW, I also ran into this issue this morning. The culprit on my end was that I was running on wkhtmltopdf v0.12.5. Upgrading to the latest version v0.12.6 sorted it.

@purcell3a
Copy link

purcell3a commented Jan 24, 2023

Also having the same issue and i'm using the latest wkhtmltopdf 0.12.6 with the current code

@SebastiaanKlippert

	page := pdf.NewPageReader(bytes.NewReader(body.Bytes()))

	// Set options for this page
	page.FooterRight.Set("[page]")
	page.FooterFontSize.Set(10)
	page.Zoom.Set(0.95)

@RomainGsd
Copy link

RomainGsd commented Mar 17, 2023

It seems to be working when wkhtmltopdf 0.12.6 with patched Qt is installed, which is not the one installed using apt.

@SebastiaanKlippert Is the patched version mandatory ?

Edit: Got my answer using pdfg.SetStderr(os.Stdout):

The switch --footer-center, is not support using unpatched qt, and will be ignored.
The switch --footer-font-size, is not support using unpatched qt, and will be ignored.
The switch --footer-left, is not support using unpatched qt, and will be ignored.
The switch --footer-line, is not support using unpatched qt, and will be ignored.
The switch --footer-right, is not support using unpatched qt, and will be ignored.
QApplication: invalid style override 'gtk2' passed, ignoring it.

@NacerKH
Copy link

NacerKH commented May 24, 2024

Issue: Qt Patch Requirement for wkhtmltopdf Version

@RomainGsd
@SebastiaanKlippert

Context

The latest version of wkhtmltopdf requires a patched version of Qt to function correctly. The following instructions outline the steps needed to set up wkhtmltopdf with header and footer capabilities.

Version

  • GO : 1.22.1
  • wkhtmltox : 0.12.6.1

Steps to Install Dependencies and wkhtmltox

  1. Update and Install Dependencies
    To ensure that all necessary dependencies are installed, run the following commands:

    apt-get update && \
    apt-get install -y --no-install-recommends \
        wget \
        fontconfig \
        fontconfig-config \
        fonts-dejavu-core \
        libbsd0 \
        libfontconfig1 \
        libfontenc1 \
        libfreetype6 \
        libjpeg62-turbo \
        libmd0 \
        libpng16-16 \
        libx11-6 \
        libx11-data \
        libxau6 \
        libxcb1 \
        libxdmcp6 \
        libxext6 \
        libxrender1 \
        sensible-utils \
        ucf \
        x11-common \
        xfonts-75dpi \
        xfonts-base \
        xfonts-encodings \
        xfonts-utils && \
    rm -rf /var/lib/apt/lists/*
  2. Download and Install wkhtmltox for Bookworm
    Download and install the specific version of wkhtmltox required:

    wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6.1-3/wkhtmltox_0.12.6.1-3.bookworm_amd64.deb && \
    dpkg -i wkhtmltox_0.12.6.1-3.bookworm_amd64.deb && \
    apt-get install -f -y && \
    rm wkhtmltox_0.12.6.1-3.bookworm_amd64.deb

Docker Image Template

To simplify the setup process, you can use the following Docker image template:

# Use the official golang image as the base image for building
FROM golang:1.22.1-bookworm AS builder

# Set the maintainer label
LABEL maintainer="NaserKh <KHALIFA.MohamedNaceur@esprit.tn>"

# Set the working directory inside the container
WORKDIR /go/src/app

# Copy the entire current directory into the container's working directory
COPY . .

# Enable Go modules
ENV GO111MODULE=on

# Install Git, Go dependencies, and additional required packages
RUN apt-get update && \
    apt-get install -y --no-install-recommends git && \
    go mod tidy && \
    go mod download

# Install necessary dependencies
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
        wget \
        fontconfig \
        fontconfig-config \
        fonts-dejavu-core \
        libbsd0 \
        libfontconfig1 \
        libfontenc1 \
        libfreetype6 \
        libjpeg62-turbo \
        libmd0 \
        libpng16-16 \
        libx11-6 \
        libx11-data \
        libxau6 \
        libxcb1 \
        libxdmcp6 \
        libxext6 \
        libxrender1 \
        sensible-utils \
        ucf \
        x11-common \
        xfonts-75dpi \
        xfonts-base \
        xfonts-encodings \
        xfonts-utils && \
    rm -rf /var/lib/apt/lists/*

# Download and install wkhtmltox for Bookworm
RUN wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6.1-3/wkhtmltox_0.12.6.1-3.bookworm_amd64.deb && \
    dpkg -i wkhtmltox_0.12.6.1-3.bookworm_amd64.deb && \
    apt-get install -f -y && \
    rm wkhtmltox_0.12.6.1-3.bookworm_amd64.deb

# Create a non-root user and home directory
RUN groupadd -r foulen && useradd -r -g foulen -d /home/foulen foulen && mkdir -p /home/foulen && chown -R foulen:foulen /home/foulen

# Set the working directory
WORKDIR /app

# Expose any necessary ports (if applicable)
EXPOSE 8080

# Switch to non-root user
USER foulen

# Start the application
CMD ["/bin/bash", "-c", "while true; do sleep 1; done"]

This Dockerfile ensures that all necessary dependencies for wkhtmltopdf are installed and configured properly, avoiding issues related to missing libraries or patches.

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

7 participants