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

set footer doesn't work #26

Closed
flrnt opened this issue Oct 31, 2018 · 9 comments
Closed

set footer doesn't work #26

flrnt opened this issue Oct 31, 2018 · 9 comments

Comments

@flrnt
Copy link

flrnt commented Oct 31, 2018

        // ...
	page := wkhtmltopdf.NewPageReader(strings.NewReader(tpl.String()))
	page.FooterRight.Set("[page]")
	page.FooterFontSize.Set(10)
	pdf.AddPage(page)
	
	errors := pdf.Create()
        // ...

Can't figure out what I'm missing to add footer in my page. Any clue ? The only page generated is OK but there is no footer at all

@SebastiaanKlippert
Copy link
Owner

Hi, your code looks fine.

I have tested this in my own tests by modifying test TestPDFGeneratorOutputFile to

func TestPDFGeneratorOutputFile(t *testing.T) {
	pdfg, err := NewPDFGenerator()
	if err != nil {
		t.Fatal(err)
	}
	htmlfile, err := os.Open("./testfiles/htmlsimple.html")
	if err != nil {
		t.Fatal(err)
	}
	defer htmlfile.Close()

	pdfg.OutputFile = "./testfiles/TestPDFGeneratorOutputFile.pdf"

	page := NewPageReader(htmlfile)

	page.FooterRight.Set("[page]")
	page.FooterFontSize.Set(10)
	pdfg.AddPage(page)

	err = pdfg.Create()
	if err != nil {
		t.Fatal(err)
	}

	pdfFile, err := os.Open("./testfiles/TestPDFGeneratorOutputFile.pdf")
	if err != nil {
		t.Fatal(err)
	}
	defer pdfFile.Close()

	stat, err := pdfFile.Stat()
	if err != nil {
		t.Fatal(err)
	}
	if stat.Size() < 100 {
		t.Errorf("generated PDF is size under 100 bytes")
	}
}

When opening this PDF, I see the page number in the footer (page 1).
Can you try the same? If it does not work for you, it might be your wkhtmltopdf version, or something in your HTML template.
You could also try to add a web page, for example page := NewPage("https://www.google.com") and see if that includes the footer, if it does, there is a problem in your template.

I have tested this on wkhtmltopdf versions 0.12.4 and 0.12.5.

If everything else fails, try from a console to call wkhtmltopdf directly with parameters --footer-right [page] --footer-font-size 10, but, because I cannot reproduce, I don't think it is an issue in my library.

@flrnt
Copy link
Author

flrnt commented Nov 19, 2018

Sorry for the late update but it doesn't seems to work. Footer does not appear even with a simple :

page := NewPage("https://www.google.com")
page.FooterRight.Set("[page]")
page.FooterFontSize.Set(10)

@grmat
Copy link

grmat commented Feb 8, 2019

I have the same issue with wkhtmltopdf 0.12.5

SebastiaanKlippert added a commit that referenced this issue Feb 8, 2019
@SebastiaanKlippert
Copy link
Owner

I have added this test which installs wkhtmltopdf 0.12.5 and then produces this PDF which prints the footer as expected.
The same happens on my Windows 10 machine with 0.12.5 and 0.12.4

So any issue you are facing is most likely not in this package, but probably a wkhtmltopdf issue.

@grmat Can you run the same test and post the output?

@grmat
Copy link

grmat commented Feb 8, 2019

Thanks for your response.

I've just ran the test and this is the result:

TestSetFooter.pdf

So yes, the problem seems to be unrelated to this project. It was the first place to look and had an issue open already. Sorry for the noise!

@SebastiaanKlippert
Copy link
Owner

Thanks for testing anyway, it is an interesting problem, best to report it at https://github.com/wkhtmltopdf/wkhtmltopdf and include your OS version.

@Limero
Copy link

Limero commented Jan 28, 2020

I have the same problem on Arch Linux with wkhtmltopdf 0.12.5. Did anyone create an upstream bug report?

@Limero
Copy link

Limero commented Feb 27, 2020

I tried running wkhmltopdf directly from the terminal with a footer option and got an error message The switch --footer-right, is not support using unpatched qt, and will be ignored..

After replacing the official Arch Linux wkhtmlpdftopdf package with wkhtmltopdf-static it works as it should.

@SebastiaanKlippert
Copy link
Owner

Good info, thanks a lot. Never used that version of wkhtmltopdf.

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

4 participants