0

I am trying to create hundreds of PDF files with TCPDF using a while loop. The problem is that it seems to create only the first one and then stops. I turned on error reporting and there is no error.

I basically get the data with:

ob_start();
while($row = mysqli_fetch_assoc($data)) { 

   $invoice_id = $row['invoice_id'];

   require_once('tcpdf_include.php');

   // create new PDF document
   $pdf = new MYCUSTOMPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
   
   // All $pdf-> settings are here

   // add a page
   $pdf->AddPage();
   $pdf->lastPage();
   $pdf->Output('/path/to/'.$invoice_id.'.pdf', 'F');
   echo "Generated ". $invoice_id."\n";

}

The .PDF gets generated fine, but it stops there. It doesn't continue with the next in the loop.

Anybody with TCPDF experience knows what is wrong? I can't figure it out and there is no error even with error_reporting(E_ALL);. Any help is greatly appreciated.

3
  • This should help stackoverflow.com/questions/16896671/… Commented Aug 9, 2020 at 2:15
  • wondering why your require_once is inside the loop. if it "has to be in the loop" because it does stuff, then require_once is the wrong require, because it will only be run once. (also, maybe it changes $data?) ;o) finally: are you certain that there's actually more than one row? Commented Aug 9, 2020 at 5:36
  • I dug into this myself and found that there is two issues with this. No answer, but wish there was. 1. When you use $pdf->Output(); it forces close(), which then cancels you to recreate another PDF. 2. The only work around that I've was unable to test, was to create a function that call during the loop. sourceforge.net/p/tcpdf/discussion/435311/thread/73dd3a84 all other options on stackoverflow did not work for me. There are older links that implies you can create a zipfile and then stuff all the pdfs into that, but I could not get that to work either. Good luck mate. Commented Jan 5, 2021 at 4:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.