urchino
urchino

Reputation: 340

mpdf dynamic HTML headers not appearing after auto page-breaks

I have a dynamically generated report PDF using mpdf, with HTML headers that are changed dynamically throughout the document. This works for all pages where I manually insert a page break and set new headers, but where the page break is caused by content overflowing the page the headers don't appear and I'm left with a blank space.

I'm using html tags to set the headers when they're updated:

<sethtmlpageheader name="page_header_<?=$profile_name ?>" value="on" show-this-page="1" />

I've tried changing this (e.g. adding a page="all" attribute) but it only makes the problem worse rather than better, in fact most of the possible solutions I've tried have caused more issues than they've fixed.

Upvotes: 2

Views: 3316

Answers (1)

karel-von-barel
karel-von-barel

Reputation: 11

Following code worked for me (after removing the show-this-page="1" attribute of the sethtmlpageheader tag) (it is a snippet from the twig template (the category variable is passed to the template from the parent one), but I guess it should work the same in other templating engines or vanilla html too):

{% set htmlPageHeaderName = "product-list-header-" ~ category.guid %}
<htmlpageheader name="{{ htmlPageHeaderName }}"> {# mPdf reserved tag #}
    <div class="product-list-header">
        <b>{{ macros.categoryHeadingWithParentsToLvl(category, "div", 0) }}</b></div>
</htmlpageheader>

<htmlpagefooter name="product-list-footer"> {# mPdf reserved tag #}
    <div class="product-list-footer">
        tel: <b>123 456 789</b>, fax: <b>123 456 788</b>, e-mail: <b>[email protected]</b>, web:<b>http://www.www.ww</b>
    </div>
    <div class="page-no">{PAGENO}</div>
</htmlpagefooter>

<sethtmlpageheader name="{{ htmlPageHeaderName }}" page="all" value="1" /> {# mPdf reserved tag #}

<sethtmlpagefooter name="product-list-footer" page="all" value="1"/> {# mPdf reserved tag #}
<columns column-count="2" valign="justify" column-gap="8"> {# mPdf reserved tag #}
    {% set categoryParents = category.parentsToLvl(1) %}
    {{ macros.categoryHeadingWithParentsToLvl(category, "h2", 1) }}
    <div class="productsList">
        {% for producerName, productsByEdition in productsByCategoryProducerEdition %}
            <div class="producerDiv">
                <h3>{{ producerName }}</h3>
                {% for editionName, products in productsByEdition %}
                    <div class="editionDiv">
    ...

Upvotes: 1

Related Questions