使多个文件将dompdf html转换为pdf为zip

时间:2017-09-28 04:53:26

标签: php codeigniter pdf zip dompdf

所有人,早上好。我有个问题。我只是使用dompdf从html到pdf进行多次导出,然后我想让我的批量导出多个zip文件。有人可以告诉我如何制作它吗?对不起我的英文不好

这是我的批量

function bulk() {

    $action = $this->input->post('action');
    if ($action == "export") {
      $export = $this->input->post('msg');

      for ($i=0; $i < count($export) ; $i++) { 

        $this->load->library('Pdfgenerator');
        $users = $this->model_csv->getDatabyDescription($export[$i]);
        $desc = $users['description'];
        $name =  substr((strrchr($desc, '-')), 2);
        $html = $this->load->view('formulir_new2', $users, true);
        $this->pdfgenerator->generate($html,"E-Tax" . time() . $name, $i);
      }


      // echo "<script type='text/javascript'>";
      //  for($i=0;$i< count($export); $i++){
      //       $users = $this->model_csv->getDatabyDescription($export[$i]);
      //       $desc = $users['description'];
      //       $name =  substr((strrchr($desc, '-')), 2);
      //       // echo "window.open('/pdf/E-tax{time()}{$name}{$i}.pdf');" ;
      //       echo "window.open('/pdf/E-Tax" . time() . $name . $i . ".pdf";
      //  }
      //  echo "</script>";

    }

这是我的pdf生成器库

public function generate($html, $filename, $i){

if($i == 0)
{
  define('DOMPDF_ENABLE_AUTOLOAD', false);
}

require_once("./vendor/dompdf/dompdf/autoload.inc.php");
$file_to_save = $_SERVER['DOCUMENT_ROOT'] . '/exportdata/uploads/pdf/';
$dompdf = new dompdf();
$options = new Options();
$options->setIsRemoteEnabled(true);
$dompdf->setOptions($options);
$dompdf->set_paper(array(0,0, 612, 936), 'portrait');
$dompdf->load_html($html);
$dompdf->render();
$abc = $dompdf->output();

file_put_contents($ file_to_save。$ filename。$ i。“。pdf”,$ abc);}

1 个答案:

答案 0 :(得分:0)

您可以使用ZipArchive

$zip = new ZipArchive ();

$zipfile = "myArchive.zip";
$zip->open ( $zipfile, ZipArchive::OVERWRITE );

for($i = 0; $i < count ( $document ); $i ++) {

    $fileinfo = pathinfo ( $document [$i] );

    if (file_exists ( $document [$i] )) {

        $zip->addFile ( $document [$i],  "myFolder/" . $fileinfo ['filename'] . "." . $fileinfo ['extension'] );
    }

}

$zip->close ();