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

--header-html not working if cover page is used #1676

Closed
harmant opened this Issue Apr 30, 2014 · 35 comments

Comments

Projects
None yet
@harmant

harmant commented Apr 30, 2014

Sample files:
https://gist.github.com/harmant/5eb432e5f9850a60991d

Test system: Ubuntu 14.04 64bit, Debian Jessie 32bit

  1. Without cover page (0.12.X) - OK:
    wkhtmltopdf --header-html header.html test.html test.pdf
    2014-04-30 13 05 14
  2. With cover page (0.12.X) (used page option) - BAD:
    wkhtmltopdf cover cover.html test.html --header-html header.html test.pdf
    2014-04-30 13 09 24
  3. With cover page (0.12.X) (used global option) - BAD:
    wkhtmltopdf --header-html header.html cover cover.html test.html test.pdf
    2014-04-30 13 10 46
  4. With cover page (0.10.rc2) (used global option) - OK:
    ./wkhtmltopdf-old --header-html header.html cover cover.html test.html test.pdf
    2014-04-30 13 11 52
  5. With cover page (0.10.rc2) (used page option) - OK:
    ./wkhtmltopdf-old cover cover.html test.html --header-html header.html test.pdf
    2014-04-30 13 14 14

P.S. --header-left, --header-right, etc. working well with cover page, problem only with --header-html

Updated: --footer-html has the same problem.

@ashkulz

This comment has been minimized.

Member

ashkulz commented Apr 30, 2014

@harmant: good bug report, but I don't know if I will find the time to fix this before 0.12.1 :-) If you submit a PR or can at least use git bisect to identify the offending commit, that would certainly help me think of a fix faster.

@ashkulz

This comment has been minimized.

Member

ashkulz commented Apr 30, 2014

I don't know how it worked for you in 0.10.0rc2, because in this commit before 0.10.0_beta1 all the header and footer settings are cleared for a cover page. Maybe @antialize can comment on this, but otherwise I can see the rationale for not having any content on a cover page.

@ashkulz ashkulz closed this Apr 30, 2014

@ashkulz ashkulz added the NotNeeded label Apr 30, 2014

@harmant

This comment has been minimized.

harmant commented May 1, 2014

Maybe, my English is not good, and you do not understand the problem. Cover page should be clear - it's OK. But all other pages in output PDF without headers - it is problem. It's a bug.

@ashkulz

This comment has been minimized.

Member

ashkulz commented May 1, 2014

Right, if that is the case it is indeed a bug.

@ashkulz ashkulz reopened this May 1, 2014

@ashkulz ashkulz removed the NotNeeded label May 1, 2014

@ashkulz ashkulz changed the title from Header-html not working if cover page used in 0.12.0 (stable), 0.12.1-dev snapshot to --header-html not working if cover page is used May 9, 2014

@harmant

This comment has been minimized.

harmant commented May 22, 2014

With --margin-top, --margin-bottom parameters cover page, headers, footers working as expected. Perhaps, problem with the auto-calculating of header/footer height.

@ashkulz

This comment has been minimized.

Member

ashkulz commented May 23, 2014

Does applying changes in #1732 produce better results?

@ashkulz

This comment has been minimized.

Member

ashkulz commented Jul 4, 2014

@harmant: the issue here was quite complex -- there were two inter-related bugs, see the commits for the actual details.

ashkulz added a commit that referenced this issue Jul 4, 2014

do not allow overriding the header/footer settings for cover pages
This was discovered in #1676, where using a command-line like:

  wkhtmltopdf cover cover.html --header-html header.html page.html output.pdf

would override the settings for the cover page and not apply the
--header-html for the URL page.html. This may be unexpected behavior
for most users, but the manual clearly states that the options FOLLOW
the URL/file name, as in:

  cover <input url/file name> [PAGE OPTION]...
  (page)? <input url/file name> [PAGE OPTION]...

So, in the above example it actually means the following

  URL1: cover cover.html --header-html header.html
  URL2: page.html
  OUT:  output.pdf

To fix this, we parse the other page options for a cover page and
then set the header/footer settings to blank values to ensure that
they are not shown on a cover page.

@ashkulz ashkulz closed this in 6a13a51 Jul 4, 2014

@ashkulz

This comment has been minimized.

Member

ashkulz commented Jul 4, 2014

FYI, I used the following set of command-line test cases while testing this issue:

wkhtmltopdf --header-html header.html page.html global_html_nocover.pdf
wkhtmltopdf --header-center "[page]"            page.html global_text_nocover.pdf
wkhtmltopdf --header-html header.html cover cover.html page.html global_html_cover.pdf
wkhtmltopdf --header-center "[page]"            cover cover.html page.html global_text_cover.pdf
wkhtmltopdf cover cover.html --header-html header.html page.html beforepage_html_cover.pdf
wkhtmltopdf cover cover.html --header-center "[page]"            page.html beforepage_text_cover.pdf
wkhtmltopdf cover cover.html page.html --header-html header.html afterpage_html_cover.pdf
wkhtmltopdf cover cover.html page.html --header-center "[page]"  afterpage_text_cover.pdf

@ashkulz ashkulz added the Fixed label Jul 4, 2014

@ashkulz ashkulz added this to the 0.12.2 milestone Jul 4, 2014

@ashkulz

This comment has been minimized.

Member

ashkulz commented Jul 8, 2014

A development snapshot 0.12.2-6a13a51 is available, which should fix this issue. Please report back if your issue is not solved with the above snapshot.

@CharlieBreval

This comment has been minimized.

CharlieBreval commented Sep 26, 2014

Yes, it resolves a problem, but creates another.
Indeed, I now got the header height on the cover page...

@ashkulz

This comment has been minimized.

Member

ashkulz commented Jan 10, 2015

0.12.2 has been released, which includes changes related to this issue.

@CharlieBreval

This comment has been minimized.

CharlieBreval commented Jan 12, 2015

Great, thanks gonna test it soon.
Thank you for the work !

@Moskydesign

This comment has been minimized.

Moskydesign commented Jan 13, 2015

I tried 0.12.2 but it still doesn't seem to work

wkhtmltopdf cover /tmp/stappenplan_pdf_cover.html --header-html /tmp/stappenplan_pdf_header.html --footer-html /tmp/stappenplan_pdf_footer.html --footer-left "Page [page] of [toPage]" /tmp/stappenplan_pdf_body.html stappenplan.pdf

@ashkulz

This comment has been minimized.

Member

ashkulz commented Jan 14, 2015

Look up above to the first post on how a bug should be reported. Just saying it doesn't work is not proper etiquette.

@daviferreira

This comment has been minimized.

daviferreira commented Mar 30, 2015

Still happens to me, --footer-spacing and --header-spacing are being added to the cover page.

My command:

wkhtmltopdf --encoding utf8 --page-size A4 --footer-html footer.html --header-html header.html --margin-left 0 --margin-right 0 --footer-spacing 20 --header-spacing 20 --user-style-sheet pdf.css cover cover.html body.html out.pdf

On a side note, I'm trying this as a hack to get different margins on the cover page, would be nice to have this as a feature 😄

@ashkulz

This comment has been minimized.

Member

ashkulz commented Apr 5, 2015

@daviferreira: please report the --footer-spacing/--header-spacing problem as a separate issue. Not sure if the margin can be changed once printing has started with QPrinter.

@kohloth

This comment has been minimized.

kohloth commented Aug 12, 2015

In reference to daviferreira commented on 30 Mar, I have this issue too. It is related to the cover.
The pdf requires margin-bottom to be set to a value (i.e. 20) for the footer to show on the PDFs pages, but setting margin-bottom means that you also get a white space at the bottom of the cover page too, which is a problem if your cover is a dark color. I issued a workaround whereby the footer-html page I specified outputs a block of color if the $page GET variable indicates its the "first page" (the cover), and then page numberings and a small logo if not. However, in my opinion it would be better if you didn't have to use margins to create a space for the footer to appear in, or if the cover did not show margins when set, only other pages.

Edit: I don't know if that was very clear.

In other words, the height of the footer that wkhtmltopdf displays is the height of the margin-bottom that you set. However, unfortunately setting a margin-bottom means that this margin also appears on the cover as a white space, which is a problem if you have a coloured cover and you need to display a footer on all the other pages.

Am trying to use the fix I mentioned above in what I think is a newer version of wkhtmltopdf, but now the footer that appears on the cover page is now just a white space, regardless of what you put in the footer html file.

Supplementary info: Im using wkhtmltopdf with the a laravel wrapper of the Snappy PHP wrapper. The wkhtmltopdf version is: wkhtmltopdf 0.12.2.1 (with patched qt)

@anvesh1

This comment has been minimized.

anvesh1 commented Nov 6, 2015

I have a solution for this and you can put this code:-

    $snappy->setOption('margin-top', 20);
    $snappy->setOption('margin-bottom', 15);
    $snappy->setOption('margin-left', '0');
    $snappy->setOption('margin-right', '0');

    $snappy->setOption('cover', 'url'');
    $snappy->setOption('header-html', 'url');
    $snappy->setOption('footer-html', 'url');

It will definitely work because i am facing the same problem and the code above resolve this.

@RiddP

This comment has been minimized.

RiddP commented Jan 3, 2016

I have exactly similar issues.
My header is 55px, footer 20px. To make header and footer visible, i have to use margin-top 55px and margin bottom 20px.
By doing so, all pages except Cover, works fine BUT, Cover gets 55px blank space at top and 20px blank space on bottom.
If I remove Margin-top or make it 0, Cover pages start from starting of page i.e works fine but from 2nd page onward, i lose header i.e no header at all.
So no solution is working for me.

Please help us. We have 15 PDF pages dynamic generated by consuming many hours. but we stuck with cover page white space and have to use some other html to pdf generating tool because of this one issue.
I have also tried to use wkhtmltopdf 0.12.2.4 but no luck.
By unknowing i added same issue #2738

@tarekmonjur

This comment has been minimized.

tarekmonjur commented Jan 13, 2016

Please anybody help me.
my footer working good,but header not working. I try this..

 \PDF::loadView('resume', $data)
      ->setPaper('a4')   
      ->setPaper('a4')
      ->setOption('margin-top', 16)
      ->setOption('margin-bottom', 12)
      ->setOption('margin-left', 0)
      ->setOption('margin-right', 0)
      ->setOption('header-html', url('load-pdf-header'))
      ->setOption('footer-html', url('load-pdf-footer'))

I use this binary..
'binary' => base_path('vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64'),
and my system is ubuntu-14.04 LTS

@krazyest

This comment has been minimized.

krazyest commented Jan 14, 2016

I can confirm that wkhtmltopdf 0.12.2.4 (with patched qt) have a problem when you have header-html / footer-html and full size cover page image.

The problem is that either you have a perfect cover page (using -T 0 -B 0 -L 0 -R 0), but then you have no headers and no footers on other pages, OR you have your headers and footers, but your cover page has blank space at the top (the size of the header).

So, currently, you can't have a full size cover page image and have headers and footers on other pages.

@jossef

This comment has been minimized.

jossef commented Jan 25, 2016

@tarekmonjur, 👍

faced the same issue, as a workaround i'm duplicating my app, creating 2 pdfs

  • cover.pdf
  • content.pdf

using this approach, i'm merging these into one file

hopes this helps for now

@krazyest

This comment has been minimized.

krazyest commented Feb 4, 2016

@jossef Little bit of pain, but your solution works! I am now using command line Pdftk to get the final document from the two. The pain was with the broken in-document links, but I have figured how to deal with that by adding a dummy cover page to the main document. So all good, thank you!

@mauriciojaramillo

This comment has been minimized.

mauriciojaramillo commented Feb 16, 2016

Hi All

"daviferreira commented on 30 Mar 2015
Still happens to me, --footer-spacing and --header-spacing are being added to the cover page.

My command:

wkhtmltopdf --encoding utf8 --page-size A4 --footer-html footer.html --header-html header.html --margin-left 0 --margin-right 0 --footer-spacing 20 --header-spacing 20 --user-style-sheet pdf.css cover cover.html body.html out.pdf

On a side note, I'm trying this as a hack to get different margins on the cover page, would be nice to have this as a feature "

This post was very usefull for me to understand the command line parameters order, thanks.

@ionut-ai

This comment has been minimized.

ionut-ai commented Feb 17, 2016

Hey,

I've been trying to get around this header / footer issue also (on version wkhtmltopdf 0.12.2.4 (with patched qt). I found a workaround that was starring me in the face.

I believe that the margins should be per section ('page', 'cover', 'toc' etc.) and not document wide, but I don't know about the QT Printer limitations. As far as I can tell, the whole pdf "printing" process is done in stages, one for the content sections (all 'page's), one for the toc, and one for the headers/footers.

First, I think the term "page" is a bit unfortunate, and I prefer to call it "section" when referring to document parts.

So, considering the scenario for my document:

  • I have a cover page (or multipe one page covers) that needs to fill the entire page, without any header and footer
  • All my document pages have headers and footers (including TOC)

As mentioned before, adding a margin-top/bottom will also add them to the cover page. I need the cover page (which in my case is ONLY one page, this is important) to disregard margins, also, I do not want to use third party tools to generate my PDF.

What I found out is that:

  • Left and right margins apply also to the header and footer which is BAD. A workaround is that these will be managed by the container element style in the page.
  • Top and bottom margin do not apply to header and footer but rather the text offset from top/bottom (section margins per page).
  • The margins do however influence the available space for the header / footer. Size for header/footer should reflect this.
  • Header/footer can bleed to content, but content cannot bleed to header/footer (out-of-bounds/negative margins do not apply).

Following my findings, and the last item above, I came up with the following solution for my cover page:

  • I am using a normal section ('page') for my cover. This means that the normal sections ('pages') need to have a page-offset of '-1' (or minus the number of covers).
  • Instead of using the content for the cover I am using the header-html (this also opens the possibility to use variables in the template). This also requires some blank content. Because webkit allows data urls I am using data:text/html, as content url.
  • In order for the header to fill the entire page the header spacing value must be the result of "margin-top" minus page-height in mm (e.g. margin-top = 31.7, A4 page results in a header-spacing of 31.7 - 297 = -265.3. As you can see negative and non integers work too.

So, to make it all work for my pseudo-cover the command should be something like this:

... --margin-top 31.7 --page-size A4 page data:text/html, --exclude-from-outline --header-spacing -265.3 --no-header-line --disable-toc-back-links --header-html cover.html page page-offset -1 ...

Hopefully this saves you some time.

@GCSBOSS

This comment has been minimized.

GCSBOSS commented May 9, 2017

@ionut-ai, I could not understand how to overcome the horizontal margins on header. Would you explain it to me in more detail?

By the way, is any of you guys ever going to fix this issue?

@stguitar

This comment has been minimized.

stguitar commented Nov 17, 2017

@krazyest Wow, i had not thought of using a dummy pdf, but thats what im now doing. For others, what i did was create an essentially blank page that goes into the WKHTMLTOPDF input list of files. my cover page is actually already a PDF file. once the main full doc is generated, i use PDFKit to strip that dummy cover page off, and then again to append the actual PDF cover page to the document.

@Jc-L

This comment has been minimized.

Jc-L commented Dec 17, 2017

@stguitar Doesn't playing with PDFKit break all bookmarks, links, and table of content in the pdf ?

@stguitar

This comment has been minimized.

stguitar commented Dec 18, 2017

@Jc-L for my use case, I actually generate the table of contents in the source HTML as just another page. This was because I have to style things appropriately. As far as links and bookmarks, the only thing i have for my documents are html anchor based links in the source HTML, and those are not impacted by my approach as mentioned above. My application compiles several HTML pages into one source html doc that goes into WKHTMLTOPDF.

@Jc-L

This comment has been minimized.

Jc-L commented Dec 21, 2017

@stguitar : you can style and generate all the table of contents by providing an xml (dump the default with --dump-default-toc-xsl and provide it after adjustments with --xsl-style-sheet). On issue is that external css does not work well in this case, but inline css does.

@jlongbottom

This comment has been minimized.

jlongbottom commented Mar 26, 2018

I have been struggling with this use case for a while now. It sounds like there is simply no way to have a full-page cover using only wkhtmltopdf, while still having headers and footers on subsequent pages.

@PleaseCallMeXiuye

This comment has been minimized.

PleaseCallMeXiuye commented Apr 19, 2018

我猜测,参数 --footer-* 和 -L -R -T -B 有冲突。
;可以正常显示页码, it work.
wkhtmltopdf --footer-right '[page]/[topage]' https://www.google.com test.pdf
;不正常,显示不了页码, it don't work.
wkhtmltopdf --footer-right '[page]/[topage]' -L 0mm -R 0mm -T 0mm -B 0mm https://www.google.com test.pdf

@yukagi

This comment has been minimized.

yukagi commented Aug 27, 2018

Is there even a way to get a full page cover (with the top and bottom margins) with header and footer on subsequent pages? I'm using header_html and footer_html for the headers/footers. This is the command I'm using:
/usr/local/bin/wkhtmltopdf --quiet --page-size Letter --margin-top 0.75in --margin-right 0.75in --margin-bottom 0.75in --margin-left 0.75in --encoding UTF-8 cover <PATH_TO>/cover_output.html --header-html <PATH_TO>/header_output.html --header-spacing 3 --footer-html <PATH_TO>/footer_output.html --footer-spacing 6 toc --xsl-style-sheet <PATH_TO>/plan.xsl - -

And I'm still just getting a cover sheet without the headers/footers.

@Jc-L

This comment has been minimized.

Jc-L commented Aug 27, 2018

@yukagi : You cannot have both headers/footers and full-page cover. Mixing both will make the reserved space for footer/headers appear on the cover page.
You can achieve what you want my cobining wkhtmltopdf with other pdf edition tools, however this is likely to break your table of contents.

@yukagi

This comment has been minimized.

yukagi commented Aug 27, 2018

@Jc-L I'm fine with the empty space (no content in header/footers) on the cover page, but I do want header/footers on the content pages. What I'm seeing is no header content anywhere when using a cover page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment