How to print cable with dynamic values in mpdf?

Asked

Viewed 461 times

-1

Personal I have a function that returns a $html containing a list of users, until here this working. my problem and when trying to generate pdf I printed header with last user of the list, not doing header reset or something similar.

I am passing the $html variable inside the method to generate header

mpdf->Setheader($html);

  • printa o html se ele tiver sair o ultimo usuario o problema é o setHeader e sim o seu html

  • not that the problem because the function is returned a user list, problem is at the time of generating pdf, the API is not making a loop for each user data by placing a header.

  • Wouldn’t it be better to use the fpdf, at least have a manual for that reason.

1 answer

2

Dude, when a doubt like that comes up go straight to documentation. The mpdf setHeader does not do what you want (iterate over a list of users and print a custom header for each). What you should do is set a different header for each page. Example based on the latest version of mpdf (taken from there):

<?php

// First ensure that you are on an Even page

$mpdf->AddPage('','E');

// Then set the headers for the next page before you add the page

$mpdf->SetHTMLHeader('<div style="text-align: right; border-bottom: 1px solid #000000; font-weight: bold; font-size: 10pt;">Chapter 2</div>','O');

$mpdf->SetHTMLHeader('<div style="border-bottom: 1px solid #000000; font-weight: bold; font-size: 10pt;">Chapter 2</div>','E');



$mpdf->AddPage();

$mpdf->SetHTMLFooter('<div style="text-align: right; font-weight: bold; font-size: 8pt; font-style: italic;">Chapter 2</div>','O');

$mpdf->SetHTMLFooter('<div style="font-weight: bold; font-size: 8pt; font-style: italic;">Chapter 2</div>','E');

$mpdf->WriteHTML('Rest of the document');

$mpdf->Output();

Basically you will scroll through your $html array, and for each index (or user) add a new page with a custom header.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.