How to break page using mPDF

Asked

Viewed 5,536 times

0

I would like to break a page to each generated document. I consulted the documentation but did not understand.

What I got is this:

$html = ob_get_clean();
ob_end_clean(); // Finaliza o fluxo

include("../../MPDF57/mpdf.php");
 
// cria um novo container PDF no formato A4 com orientação customizada
$mpdf=new mPDF('pt','A4',3,'',8,8,5,14,9,9,'P');
 
// muda o charset para aceitar caracteres acentuados iso 8859-1 utilizados por mim no banco de dados e na geracao do conteudo PHP com HTML
$mpdf->allow_charset_conversion=true;
$mpdf->charset_in='iso-8859-1';
 
//Algumas configurações do PDF
$mpdf->SetDisplayMode('fullpage');
// modo de visualização
$rodape = '{DATE j/m/Y H:i}|{PAGENO}/{nb}| Gerado automaticamente pelo Sistema';
$mpdf->SetFooter($rodape);
//bacana este rodape, nao eh mesmo?
 
// carrega uma folha de estilo - MAGICA!!!
$stylesheet1 = file_get_contents('../../css/stgeral.css');
$stylesheet2 = file_get_contents('../../bootcocari/css/bootstrap.min.css');
$stylesheet3 = file_get_contents('../../bootcocari/css/bootstrap.icon-large.css');
$stylesheet4 = file_get_contents('../css/styleCurriculo.css');
 
// incorpora a folha de estilo ao PDF
// O parâmetro 1 diz que este é um css/style e deverá ser interpretado como tal
$mpdf->WriteHTML($stylesheet1,1);
$mpdf->WriteHTML($stylesheet2,1);
$mpdf->WriteHTML($stylesheet3,1);
$mpdf->WriteHTML($stylesheet4,1);
 
// incorpora o corpo ao PDF na posição 2 e deverá ser interpretado como footage. Todo footage é posicao 2 ou 0(padrão).
$mpdf->WriteHTML($html,2);
 
// define um nome para o arquivo PDF
$arquivo = date("dmy_"). '_curriculos.pdf';
 
// gera o relatório
$mpdf->Output($arquivo,'I');
 
exit();
  • Hello You want to force a second page?

  • Hello @Rafaelmenabarreto, yes, for example, Gero 10 pages and would like to be able to break page to each one that is generated.

2 answers

1


In the library mpdf the method to create a new page is addPage. This method can be used every time you want to create a page in a forced way, that is, when you want the new page to start independently of the free space on the previous page.

$mpdf->AddPage();

The whole $mpdf->writeHtml() that you send after that goes to the new page. If you have 10 pages you will have to use the method 10 times or through a foreach.

  • In which position I use this command at the end of the code?

  • Every time you need to create a new page.

  • Good morning, @Rafaelmenabarreto. I have a report that will be printed 25 lines per page. Let’s say I have 300 pages to print. How would I do that. Wouldn’t it be better to use a for instead of a foreach? You would have a clearer example, pfv.

0

To force the page break just add $html .= '<pagebreak />'; after the item you want to play on another page.

If you are using loop loop for example while, just do it as follows:

while:

  <tabe></table>

  $html .= '<pagebreak />';

endwhile;

Browser other questions tagged

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