2019独角兽企业重金招聘Python工程师标准>>>
这个有点复杂的,我们一步一步来说明。
受先我们要下载pdf需要的文件,搜索‘php生成pdf’找到相关进行下载,这里不做介绍
//pdf下载$name = $_SESSION['ex_uname'];$name_pdf=$name.'.pdf';$url = $_SERVER['DOCUMENT_ROOT']."/static/download/".$name;if (false == file_exists($url.'/'.$name_pdf)) { $name = $_SESSION['ex_uname'];$url = $_SERVER['DOCUMENT_ROOT']."/static/download/".$name;@mkdir ( $_SERVER['DOCUMENT_ROOT']."/static/download/".$name, 0777 );//新建文件夹//echo dirname(dirname(__FILE__)).'/static/pdf/tdpdf/tcpdf_autoconfig.php';exit;require_once($_SERVER['DOCUMENT_ROOT'].'/static/pdf/tcpdf/tcpdf.php');require_once($_SERVER['DOCUMENT_ROOT'].'/static/pdf/opendir.php');$var_array = require($_SERVER['DOCUMENT_ROOT'].'/static/pdf/signconfig.php');$str_array = require($_SERVER['DOCUMENT_ROOT'].'/static/pdf/rayconfig.php');class MYPDF extends TCPDF {public function Header() {$bMargin = $this->getBreakMargin();$auto_page_break = $this->AutoPageBreak;$this->SetAutoPageBreak(false, 0);$this->SetAutoPageBreak($auto_page_break, $bMargin);$this->setPageMark();}}$id = $_SESSION['ex_uid'];$str = APP::M('advset')->get_exlist($id);$companyname = $str['companyname'];$username = $str['username'];$fullname = $str['fullname'];$telphone = $str['telphone'];$address = $str['address'];$fax = $str['fax'];$email = $str['email']; //print_r($str);exit;//实例化类并设置一些PDF属性$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);$pdf->SetCreator(PDF_CREATOR);$pdf->SetAuthor('Note');$pdf->SetTitle('Note');$pdf->SetSubject('TCPDF Tutorial');$pdf->SetKeywords('TCPDF,文件');$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);$pdf->SetHeaderMargin(0);$pdf->SetFooterMargin(0);$pdf->setPrintFooter(false);$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);//调用遍历文件的类$biao = new opdirsign();$jet = $biao->kob();$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);$i=1;foreach($jet as $key=>$value){//添加新的一页$pdf->AddPage();$bMargin = $pdf->getBreakMargin();$auto_page_break = $pdf->getAutoPageBreak();$pdf->SetAutoPageBreak(false, 0);$img_file = K_PATH_IMAGES.'sign/'.$value["name"];$pdf->Image($img_file, 0, 0, 210, 297, '', '', '', true, 300, '', false, false, 0);$pdf->SetAutoPageBreak($auto_page_break, $bMargin);$pdf->setPageMark();$pdf->SetFont('cid0cs', '', 10);//这里开始定位$bot = explode(",",$var_array[$i]['firm']);$bot[0] == 0 && $bot[1] ==0?" " :$pdf->writeHTMLcell($bot[0],$bot[1],$bot[2],$bot[3],$companyname, 0, 0, false, false, '',0,0);$jot = explode(",",$var_array[$i]['address']);$jot[0] == 0?" ":$pdf->writeHTMLcell($jot[0],$jot[1],$jot[2],$jot[3],$address, 0, 0, false, false, '',0,0);$aot = explode(",",$var_array[$i]['booth']);$aot[0] ==0?" ":$pdf->writeHTMLcell($aot[0],$aot[1],$aot[2],$aot[3],$username, 0, 0, false, false, '',0,0);$cot = explode(",",$var_array[$i]['touch']);$cot[0] == 0?" ":$pdf->writeHTMLcell($cot[0],$cot[1],$cot[2],$cot[3],$fullname, 0, 0, false, false, '',0,0);$dot = explode(",",$var_array[$i]['tel']);$dot[0] == 0 ?" ":$pdf->writeHTMLcell($dot[0],$dot[1],$dot[2],$dot[3],$fax, 0, 0, false, false, '',0,0);$eot = explode(",",$var_array[$i]['fax']);$eot[0] == 0 ?" " :$pdf->writeHTMLcell($eot[0],$eot[1],$eot[2],$eot[3],$telphone, 0, 0, false, false, '',0,0);$fot = explode(",",$var_array[$i]['email']);$fot[0] == 0 ?" ":$pdf->writeHTMLcell($fot[0],$fot[1],$fot[2],$fot[3],$email, 0, 0, false, false, '',0,0);$hot = explode(",",$var_array[$i]['phone']);$hot[0] == 0 ?" " :$pdf->writeHTMLcell($hot[0],$hot[1],$hot[2],$hot[3],$phone, 0, 0, false, false, '',0,0);$i++;}$iconv = iconv("UTF-8","gbk//TRANSLIT","资料下载");//echo $mingz;exit;$pdf->Output($name.'_optional.pdf', 'd');$pdf->Output($url.'/'.$name.'_optional_'.$iconv.'.pdf', 'F');
}