use setasign\Fpdi\Fpdi;
use think\facade\Env;
use library\File;
public function pdf($user, $path)
{
$pdf = new Fpdi();
$pageCount = $pdf->setSourceFile($path);
$pdf->AddGBFont('simhei', '黑体');
$pdf->SetFont('simhei', '', 12);
for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
$templateId = $pdf->importPage($pageNo);
$pdf->AddPage();
$pdf->useTemplate($templateId);
if ($pageNo == 1) {
$pdf->SetXY(75, 179);
$pdf->Write(5, $user['pay']);
$pdf->SetXY(25, 210);
$pdf->Write(5,iconv("utf-8","gbk",$v['title']));
} else if($pageNo == 2) {
}
}
$fileName = time().'.pdf';
if (strtoupper(substr(PHP_OS,0,3)) === 'WIN') {
$url = Env::get('ROOT_PATH')."public\uploads\contract\\".$fileName;
} else {
$url = Env::get('ROOT_PATH').'public/uploads/contract/'.$fileName;
}
$pdf->Output($url,'F');
$pdf->closeParsers();
$res = File::save($fileName,file_get_contents($url));
if($res) {
unlink($url);
return $res['url'];
}else{
return false;
}
}
如果您觉得本篇对你有帮助,可以点关注,给个赞,支持一下,过程有遇到什么问题也欢迎评论私信,进行交流
|