使多个文件转换dompdf html到pdf到zip
问题描述:
早上好。我有个问题。我只是使用dompdf将多个输出从html转换为pdf,然后我想通过批量将多个输出转换为zip文件。有没有人可以告诉我如何做到这一点?注:对不起,我的英语不好使多个文件转换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 $文件名$ I “PDF”,$。 ABC);}
答
你可以使用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();
+0
您好,非常感谢您的帮助,但您能否给我演示? –
+0
在我的示例中,文档是一个数组,它包含您生成的所有pdf。所以你可以把'$ document = array($ file_to_save。$ filename)' – Max
你的代码中有什么问题?请提一下,没有人会在这里为您编写代码:P – Bira