php uses mpdf to generate pdf and save it to a directory

There are two ways to download mpdf7.0

(1), github address: https://github.com/mpdf/mpdf

(2)、 composer require mpdf/mpdf

<?php
error_reporting(0);
set_time_limit(0);
include('../common/conn.php');
require_once __DIR__ . '/../vendor/autoload.php';
$mpdf = new \Mpdf\Mpdf();
$sign=@$_GET['sign'];
if($sign==''){
    //获取全部门店信息
    $branch="SELECT top 2 a.cCusCode,a.cCusName,a.cCusPerson,a.cCusPhone,a.cCusHand,a.cCusOAddress,c.cDepName FROM dbo.Customer a LEFT JOIN dbo.CustomerClass b on a.cCCCode=b.cCCCode LEFT JOIN dbo.Department c on a.cCusDepart=c.cDepCode where b.cCCCode like '300%'";
}else{
    $branch="SELECT a.cCusCode,a.cCusName,a.cCusPerson,a.cCusPhone,a.cCusHand,a.cCusOAddress,c.cDepName FROM dbo.Customer a LEFT JOIN dbo.CustomerClass b on a.cCCCode=b.cCCCode LEFT JOIN dbo.Department c on a.cCusDepart=c.cDepCode where a.cCusCode ='$sign'";
}
$branchList=$db->getAll($branch);
$branchList=array_iconv($branchList);
if(is_array($branchList) && count($branchList)){
    foreach($branchList as $key=>$val){
        $html = file_get_contents("http://172.16.6.20:2222/pdf/branch.php?sign=$val[cCusCode]"); //加载要生成pdf的文件
        //Set the pdf display mode
        $mpdf->SetDisplayMode('fullwidth');
        $mpdf->autoScriptToLang = true;
        $mpdf->autoLangToFont = true;
        $mpdf->WriteHTML($html);
        $filename= iconv("utf-8","gb2312",$val['cCusName']).".pdf";
        $path="./files/".$filename;
        $mpdf->Output($path,'f' ); //Save to the current file folder
    }
}
?>

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324843899&siteId=291194637