The task is to create 2 pdf files in a row with different content. I tried this:

$mpdf->WriteHTML($html, 2); $mpdf->Output($file, 'F'); $mpdf->WriteHTML($html1, 2); $mpdf->Output($file1, 'F'); 

The first one recorded normally, in the second one I shoved the first one and there is no hint of $ html1. I tried to search for file cleaning or did not find closing. Pliz tell me what I do not see.

  • $mpdf->WriteHTML($html, 2, true, true) haven't you tried this? - Ninazu
  • added .. the same gives out - Durrasell
  • Well then it is clumsy. Create another object, $mpdf2 = new mPDF(); or use $mpdf2 clone $mpdf; if there is a lot of logic before the output goes - Ninazu

1 answer 1

Option 1

 function SavePDF($html, $file){ $mpdf = new mPDF(); //Тут остальная логика $mpdf->WriteHTML($html, 2); $mpdf->Output($file, 'F'); } for($i=1;$i<5;$i++){ SavePDF("<div>Hello</div>", __DIR__ . '/report_' . time() . '.pdf'); } 

Option 2

 $mpdf = new mPDF(); //Тут остальная логика for($i=1;$i<5;$i++){ $clonedMpdf clone $mpdf; $mpdf->WriteHTML("<div>Hello</div>", 2); $mpdf->Output(__DIR__ . '/report_' . time() . '.pdf', 'F'); unset($clonedMpdf); } 

https://raw.githubusercontent.com/mpdf/mpdf/development/src/Mpdf.php Do you use this version? Having rummaged in the code noticed these methods

 $mpdf->Reset(); $mpdf->DeletePages(0); 

Maybe they will help.

  • the methods didn't work - Durrasell
  • I will try now with class cloning - Durrasell
  • The clone worked but the html itself from the file disappeared .. recorded as text - Durrasell
  • And the first option? - Ninazu
  • The situation is this .. I have a class that uses the namespace. inside the method, if you call new mPDF (); it says that there is no such class. I in the file where the class method is called in the parameters passed two initialized copies of the mPDF with different variables and went - Durrasell