“Repeat Header and Footer” is not working as expected for custom print formats

When we switch to the documented approach using #header-html and #footer-html together with print_settings.repeat_header_footer, the header is only rendered on the first page and the footer only on the last page, not repeated on each page as expected.

My Setup

Header

    {% if letter_head and not no_letterhead %}
      {% if print_settings.repeat_header_footer %}
        <div id="header-html" class="visible-pdf">
          <div class="letter-head">
            {{ letter_head }}
          </div>
        </div>
      {% else %}
        <div id="header">
          {{ letter_head }}
        </div>
      {% endif %}
    {% endif %}

Footer

    {% if print_settings.repeat_header_footer %}
      <div id="footer-html" class="visible-pdf">
        {% if footer and not no_letterhead %}
          <div class="letter-head-footer">
            {{ footer }}
          </div>
        {% endif %}
        <p class="text-center text-small page-number visible-pdf">
          {{ _("Page {0} of {1}").format('<span class="page"></span>', '<span class="topage"></span>') }}
        </p>
      </div>
    {% else %}
      {% if footer and not no_letterhead %}
        <div class="letter-head-footer">
          {{ footer }}
        </div>
      {% endif %}
    {% endif %}

Context information (for bug reports)

Output of bench version

bench v5.27.0

Steps to reproduce the issue

  1. Create a custom print format for a multi-page document (e.g. long item table).
  2. Place header and footer in
{% if print_settings.repeat_header_footer %}
  <div id="header-html">
    {{ letter_head }}
  </div>
{% endif %}
  1. Enable “Repeat Header and Footer” in Print Settings.
  2. Print the document as PDF (using the built-in PDF button).

Observed result

Header only printed on first page. Footer printed on last and if content expands on a second page to new page.

Expected result

Header and footer should be placed in each page at top and bottom. Content should respect header and footer.

Additional information

ERPNext: v15.88.1

Frappe: v15.88.1

wkhtmltopdf: 0.12.6 (patched qt)


Already tried:

ERPnext UI
So i found the “solution” (more an UI/UX-Issue than a bug)

The button PDF is the correct one which uses the wkhtmltopdf engine.
The Drucken (print) Button uses the browser to render the PDF. Because of this, every wkhtmltopdf part will not be read correctly.