Add page break after match of certain class on div with mpdf

user2031297 picture user2031297 · Jan 21, 2014 · Viewed 27k times · Source

I am converting a report (in html)to pdf using mPDF library, but is putting all pages into one. I want to add a page break after a certain but I haven't been successful.

html

 <div class='text my_form' style='margin:0px 0 0 0; padding:0px 0 0 0;  border-style:dotted; border-color:white;'>

I'm passing this to the php as $html

PHP

 require_once ("./libraries/MPDF57/mpdf.php");

    $mpdf=new mPDF("", "Letter", "", "", 10, 10);

I want to add a page break after it finds the div shown above

 preg_match_all("/((\<div\s)(class='text\smy_form'[\s\w\s]*border-color:white)(.+?)(\>)/", $html, $matches, PREG_SET_ORDER);

    foreach($matches as $value) {
       $html= $mpdf->AddPage();
     }

     $mpdf->WriteHTML($html);

     $filename = "documentx.pdf";

    $mpdf->Output($fileName, 'F');

However, is not working, please help me go through the right track :)

Answer

jpx3m picture jpx3m · Mar 30, 2014

I use this code before closing the foreach tag: $html .= "&lt;pagebreak /&gt;";

foreach($matches as $value) {
   $html .= "<pagebreak />";
 }