1.composer安装PDF组件
composerrequiresetasign/fpdi
composerrequiresetasign/fpdf
两个组件都需要安装,有依赖关系
2.使用
<?php
try{
$fpdi=newFpdi();
//设置待处理PDF文件,并且方法返回PDF总计页数
$pagecount1=$fpdi->setSourceFile("C:\Users\83553\Desktop\pdf\员工保密协议(2).pdf");
for($i=1;$i<=$pagecount1;$i++){
//增加新的空白PDF页面
$fpdi->AddPage();
//导入页面
$tplId=$fpdi->importPage($i);
//填充页面
$fpdi->useTemplate($tplId);
}
//以下同理,因为多个PDF文件,所以多次,需要合并的PDF文件过程,可以使用循环,次示例仅供参考(示例可跑通)
$pagecount2=$fpdi->setSourceFile("C:\Users\83553\Desktop\pdf\怎样写好工作总结(1).pdf");
for($j=1;$j<=$pagecount2;$j++){
$fpdi->AddPage();
$tplIdkk=$fpdi->importPage($j);
$fpdi->useTemplate($tplIdkk);
}
$pagecount3=$fpdi->setSourceFile("C:\Users\83553\Desktop\pdf\租房协议书.pdf");
for($k=1;$k<=$pagecount3;$k++){
$fpdi->AddPage();
$tplIdoo=$fpdi->importPage($k);
$fpdi->useTemplate($tplIdoo);
}
//D代表下载I代表预览F代表保存S代表返回String
$fpdi->Output("D","test.pdf");
}catch(\Exception$exception){
echo$exception->getMessage();
}
|