I want to create multiple pdfs in a loop using dompdf?

前端 未结 1 1806
一个人的身影
一个人的身影 2021-01-20 19:11

I want to generate multiple pdf files in loop using dompdf. I am using dompdf_0-6-0_beta3. But only one file get generated each time wehn I execute the code. I am providing

相关标签:
1条回答
  • 2021-01-20 19:32

    You'l have to save your all PDFs to server and then redirect User to download these PDFs.

    include 'dompdf_config.inc.php';
    
    $file_to_save = '/path/to/your/public_html/pdf/';
    
    for($i=0; $i<5; $i++)
    {
      if ( get_magic_quotes_gpc() )
          $old_limit = ini_set("memory_limit", "16M");
    
      $dompdf = new DOMPDF();
      $dompdf->load_html($i);
      $dompdf->set_paper('a4', 'portrait');
      $dompdf->render();
    
      //Save PDF in server.
      file_put_contents($file_to_save."file".$i.".pdf", $dompdf->output()); 
    
     } 
    
     //open popup window to download all PDFs to client browser.
     echo "<script type='text/javascript'>";
     for($i=0;$i<5: $i++){
          echo "window.open('/pdf/file{$i}.pdf');" ;
     }
     echo "</script>";
    
    0 讨论(0)
提交回复
热议问题