$param = request()->all();
//Log::info('输出变量:', ['$param' => $param]);
$id = getter($param, "id", 0);
if (!isset($id[0]) || empty($id[0])) {
return message("请选择需要生成PDF文档的学生", false);
}
$sMode = new StudentModel();
$sinfo= $sMode->getInfo($id[0]);
Log::debug($sinfo);
if($sinfo){
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
//$pdf = new \TCPDF();
// 设置文档信息
$pdf->SetCreator('湖南匠领科技有限公司');
$pdf->SetAuthor('湖南匠领科技有限公司');
$pdf->SetTitle($sinfo['name']);
$pdf->SetSubject('湖南匠领科技有限公司');
$pdf->SetKeywords('湖南匠领科技有限公司');
// 设置页眉和页脚信息
$pdf->SetHeaderData('123', 30, 'www.bekingai.com', '湖南匠领科技有限公司', [0, 64, 255], [0, 64, 128]);
$pdf->setFooterData([0, 64, 0], [0, 64, 128]);
// 设置页眉和页脚字体
$pdf->setHeaderFont(['stsongstdlight', '', '10']);
$pdf->setFooterFont(['helvetica', '', '8']);
// 设置默认等宽字体
$pdf->SetDefaultMonospacedFont('courier');
// 设置间距
$pdf->SetMargins(15, 15, 0);//页面间隔
$pdf->SetHeaderMargin(5);//页眉top间隔
$pdf->SetFooterMargin(10);//页脚bottom间隔
// 设置分页
$pdf->SetAutoPageBreak(true, 25);
// set default font subsetting mode
$pdf->setFontSubsetting(true);
//设置字体 stsongstdlight支持中文
$pdf->SetFont('stsongstdlight', '', 14);
//第一页 $sinfo["name"]
$pdf->AddPage();
$html = '
<table width="90%" border="1" cellpadding="15">
<tr>
<td colspan="2" height="220"></td>
<td colspan="2"></td>
</tr>
<tr>
<td width="25%">姓名</td>
<td width="25%">'.$sinfo['name'].'</td>
<td width="25%">性别</td>
<td width="25%">'.$sinfo['gender_name'].'</td>
</tr>
<tr>
<td>学号</td>
<td>'.$sinfo['code'].'</td>
<td>身份号码</td>
<td>'.$sinfo['id_code'].'</td>
</tr>
<tr>
<td>班级</td>
<td>'.$sinfo['class_name'].'</td>
<td>年级</td>
<td>'.$sinfo['grade_name'].'</td>
</tr>
<tr>
<td>出生日期</td>
<td>'.$sinfo['birthday_out'].'</td>
<td>有效状态</td>
<td>'.$sinfo['status_name'].'</td>
</tr>
<tr>
<td>联系电话</td>
<td>'.$sinfo['telephone'].'</td>
<td>结业状态</td>
<td>'.$sinfo['finish_status'].'</td>
</tr>
<tr>
<td>详细住址</td>
<td colspan="3">'.$sinfo['address'].'</td>
</tr>
<tr>
<td>备注</td>
<td colspan="3">'.$sinfo['intro'].'</td>
</tr>
</table>
';
$pdf->writeHTML('<div style="text-align: center"><h1>'.$sinfo["name"].'</h1></div>');
$pdf->writeHTML($html);
//头像
if($sinfo['avatar']){
$pdf->SetXY(20, 50);
$pdf->Image($sinfo['avatar'], '', '', 0, 0, '', '', '', false, 300, '', false, false, 0, false, false, false);
}
Log::debug('头像地址:'.$sinfo['avatar']);
//二维码
if($sinfo['logo']){
$pdf->SetXY(110, 50);
$pdf->Image($sinfo['logo'], '', '', 0, 0, '', '', '', false, 300, '', false, false, 0, false, false, false);
}
$pdf->Ln(1);//换行符
$fileName = date('YmdHms').'.pdf';
//输出PDF
$pdf->Output(UPLOAD_TEMP_PATH . "/" .$fileName, 'F');//I输出、D下载、 F保存到服务器
// 下载地址
$fileUrl = get_image_url(str_replace(ATTACHMENT_PATH, "", UPLOAD_TEMP_PATH) . "/" . $fileName);
Log::debug('下载地址:'.$fileUrl);
return message(MESSAGE_OK, true, $fileUrl);
}
return message("操作失败", false);