pdf2img_url = 'https://liche-api-dev.xiaoyu.com/jar/pdf2img'; } } /** * html转pdf * @param $html_url string 网页地址 * @param $path string 保存文件路径 * @param $filename string 保存文件名 */ public function html2pdf($html_url,$path,$filename){ if (!file_exists($path)){ $oldumask = umask(0); mkdir($path, 0777, true); umask($oldumask); } $arrContextOptions=array( "ssl"=>array( "verify_peer"=>false, "verify_peer_name"=>false, ), ); $html = file_get_contents($html_url,false,stream_context_create($arrContextOptions)); $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT,true, 'UTF-8', false); $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor("liche"); $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); $pdf->setCellHeightRatio(1.1); //设置行高 $pdf->SetMargins(PDF_MARGIN_LEFT, 5,PDF_MARGIN_RIGHT); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); $pdf->SetFont('simsun', '', 10); //设置中文显示 $pdf->AddPage(); $pdf->writeHTML($html, true, false, true, false, ''); $save = $path.'/'.$filename; $pdf->Output($save,'F'); if(file_exists($save)){ return true; }else{ return false; } } /* * 图片转pdf * @param $pdf_url staring pdf文件url地址 * @return $result array() 返回图片数组 ['',''] */ public function pdf2img($pdf_url){ $ci = & get_instance(); $ci->load->library('mycurl'); $url = $this->pdf2img_url.'?furl='.$pdf_url; $result = $ci->mycurl->httpGet($url); $result = json_decode($result,true); return $result['data'] ? $result['data'] : false; } }