TCPDF生成PDF文件,含jpjraph生成雷达图
依赖自行安装
"tecnickcom/tcpdf": "^6.6",
"amenadiel/jpgraph": "4"
雷达图生成
中文字体添加安装
没有封装,只作为测试案例展示
$pdf = new \TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetPrintHeader(false);
$pdf->SetPrintFooter(false);
$pdf->SetAutoPageBreak(false);
$pageWidth = $pdf->getPageWidth();
$pageHeight = $pdf->getPageHeight();
$titleFont = 'yahei';
$titleFontSize = 16;
$pdf->AddPage();
$cover_img = 'https://******.png';
$pdf->Image($cover_img, 0, 0, $pageWidth, $pageHeight);
$pdf->SetTextColor(0,0,0);
$pdf->SetFont($titleFont, '', $titleFontSize-6);
$pdf->Text(23, 275, '扫一扫在线浏览报告');
$pdf->SetTextColor(0,0,0);
$pdf->SetFont($titleFont, '', $titleFontSize-6);
$pdf->Text(18, 30, '报告编号:');
$dateTime = new \DateTime($row['create_time']);
$yearMonthDay = $dateTime->format('Y-m-d');
$pdf->Text(157, 265, '自测时间:'.$yearMonthDay);
$pdf->Text(115, 271, '报告提供单位:');
$pdf->SetTextColor(67, 16, 16);
$pdf->SetFont($titleFont, '', $titleFontSize+3);
$pdf->Text($pdf->GetX()-180, $pdf->GetY()-145, $qy_data['Name'] ?? '');
$pdf->AddPage();
$headerImgPath = 'https://*****.png';
$footerImgPath = 'https://******.png';
$headerImgHeight = 30;
$footerImgHeight = 30;
$pdf->Image($headerImgPath, 0, 0, $pageWidth, $headerImgHeight, '', '', '', false, 300, '', false, false, 0);
$pdf->Image($footerImgPath, 0, 267, $pageWidth, $footerImgHeight, '', '', '', false, 300, '', false, false, 0);
$pdf->SetFont($titleFont, '', 8);
$pdf->SetTextColor(144, 144, 144);
$pdf->Text($pdf->GetX()+8, $pdf->GetY()+2, $qy_data['Name']);
$titleWidth = $pageWidth - 20;
$titleHeight = 15;
$titleBackgroundColor = array(0, 130, 237);
$titleTextColor = array(255, 255, 255);
$pdf->SetFillColor($titleBackgroundColor[0], $titleBackgroundColor[1], $titleBackgroundColor[2]);
$pdf->SetTextColor($titleTextColor[0], $titleTextColor[1], $titleTextColor[2]);
$pdf->SetFont($titleFont, 'B', $titleFontSize);
$pdf->Rect(10, 25, $titleWidth, $titleHeight, 'F');
$titleText = '企业概要';
$pdf->Text(12, 29, $titleText);
$pdf->SetTextColor(0,0,0);
$pdf->SetFont($titleFont, '', 12);
$pdf->Text(12, 45, '企业基本信息数据来源于测试主体在相关信息公示、公开信息数据整理分析所得');
$pdf->SetFillColor(95, 183, 255);
$pdf->SetTextColor($titleTextColor[0], $titleTextColor[1], $titleTextColor[2]);
$pdf->Rect(10, 55, $titleWidth, $titleHeight-2, 'F');
$pdf->SetFont($titleFont, 'B', 12);
$titleText = '基本信息';
$pdf->Text(12, 59, $titleText);
$pdf->Ln(12);
$pdf->SetTextColor(0,0,0);
$pdf->SetFont($titleFont, '', 8);
$data = [
['企业名称', $qy_data['Name'] ?? '', '统一社会信用代码', $qy_data['CreditCode'] ?? ''],
['法人代表', $qy_data['OperName'] ?? '', '注册资本', $qy_data['RegistCapi'] ?? ''],
['企业类型', $qy_data['EconKind'] ?? '', '登记状态', $qy_data['Status'] ?? ''],
['成立日期', $qy_data['StartDate'] ? date('Y-m-d',strtotime($qy_data['StartDate'])) : '', '核准日期', $qy_data['CheckDate'] ? date('Y-m-d',strtotime($qy_data['CheckDate'])) : ''],
['营业期限', date('Y-m-d',strtotime($qy_data['TermStart'])).'至'.$qy_data['TeamEnd'] ? date('Y-m-d',strtotime($qy_data['TeamEnd'])) :'无固定期限', '登记机关', $qy_data['BelongOrg'] ?? ''],
];
$tHeight = 30;
foreach ($data as $key => $val) {
foreach ($val as $colIndex => $cell) {
if ($colIndex == 0 || $colIndex == 2) {
$pdf->SetFillColor(244, 244, 244);
$tWidth = 30;
$align = 'C';
} else {
$pdf->SetFillColor(255, 255, 255);
$tWidth = 65;
$align = 'L';
}
$pdf->Cell($tWidth, 10, $cell, ['LTRB' => ['width' => 0.1, 'color' => array(233, 233, 233)]], 0, $align, 1);
}
$pdf->Ln();
}
$tWidth = 30;
$pdf->SetFillColor(244, 244, 244);
$pdf->Cell($tWidth, 10, '注册地址', 1, 0, 'C',1);
$pdf->SetFillColor(255, 255, 255);
$pdf->Cell($tWidth + 130, 10, $qy_data['Address']??'', ['LTRB' => ['width' => 0.1, 'color' => array(233, 233, 233)]], 1, 'L', 1, '', 3);
$pdf->SetFillColor(244, 244, 244);
$contentHeight = $pdf->GetStringHeight($tWidth + 130,$qy_data['Scope']??'');
$rowHeight = max(10, $contentHeight)+2;
$pdf->Cell($tWidth, $rowHeight, '经营范围', 1, 0, 'C',1);
$pdf->MultiCell($tWidth + 130, $rowHeight, $qy_data['Scope']??'', ['LTRB' => ['width' => 0.1, 'color' => array(233, 233, 233)]], 'L', 0, 1,'', '', true, 0, false, true, $rowHeight, 'M');
$data = $qy_datas['t']['Result'];
if(!$data){
$data = [
[
"KeyNo" => "-",
"StockName" => "-",
"StockType" => "-",
"StockPercent" => "-",
"ShouldCapi" => "-",
"ShoudDate" => "-",
"StakeDate" => "-",
"CreditCode" => "-"
]
];
}
if ($pdf->GetY() + 20 > $pdf->getPageHeight()) {
$pdf->AddPage();
$pdf->Image($headerImgPath, 0, 0, $pageWidth, $headerImgHeight, '', '', '', false, 300, '', false, false, 0);
$pdf->Image($footerImgPath, 0, 267, $pageWidth, $footerImgHeight, '', '', '', false, 300, '', false, false, 0);
$pdf->SetFont($titleFont, '', 8);
$pdf->SetTextColor(144, 144, 144);
$pdf->Text($pdf->GetX()+8, $pdf->GetY()+2, $qy_data['Name']);
$pdf->Ln(12);
}
$pdf->SetFont($titleFont, 'B', 12);
$pdf->SetFillColor(95, 183, 255);
$pdf->SetTextColor($titleTextColor[0], $titleTextColor[1], $titleTextColor[2]);
$pdf->Rect($pdf->GetX(), $pdf->GetY()+3, $titleWidth, $titleHeight-2, 'F');
$titleText = '企业投资人信息';
$pdf->Text(12, $pdf->GetY()+7, $titleText);
$pdf->Ln(12);
foreach ($data as $key => $val) {
if ($pdf->GetY() + 30 > $pdf->getPageHeight()) {
$pdf->AddPage();
$pdf->Image($headerImgPath, 0, 0, $pageWidth, $headerImgHeight, '', '', '', false, 300, '', false, false, 0);
$pdf->Image($footerImgPath, 0, 267, $pageWidth, $footerImgHeight, '', '', '', false, 300, '', false, false, 0);
$pdf->SetFont($titleFont, '', 8);
$pdf->SetTextColor(144, 144, 144);
$pdf->Text($pdf->GetX()+8, $pdf->GetY()+2, $qy_data['Name']);
$pdf->Ln(12);
}
$pdf->SetTextColor(0,0,0);
$pdf->SetFont($titleFont, '', 8);
$pdf->SetFillColor(244, 244, 244);
$pdf->Cell(30, 10, '投资人姓名', 1, 0, 'C', 1);
$pdf->SetFillColor(255, 255, 255);
$pdf->Cell(65, 10, $val['StockName'], 1, 0, 'L', 1);
$pdf->SetFillColor(244, 244, 244);
$pdf->Cell(30, 10, '投资人类型', 1, 0, 'C', 1);
$pdf->SetFillColor(255, 255, 255);
$pdf->Cell(65, 10, $val['StockType'], 1, 1, 'L', 1);
$pdf->SetFillColor(244, 244, 244);
$pdf->Cell(30, 10, '持股比例', 1, 0, 'C', 1);
$pdf->SetFillColor(255, 255, 255);
$pdf->Cell(65, 10, $val['StockPercent'], 1, 0, 'L', 1);
$pdf->SetFillColor(244, 244, 244);
$pdf->Cell(30, 10, '认缴出资额', 1, 0, 'C', 1);
$pdf->SetFillColor(255, 255, 255);
$pdf->Cell(65, 10, $val['ShouldCapi'], 1, 1, 'L', 1);
$pdf->Ln(2);
}
$data = $qy_datas['z']['Result']['Data'];
if(!$data){
$data = [
[
"Name" => "-",
"Level" => "-",
"Source" => "-",
"PublishOffice" => "-",
"PublishDate" => "-",
"BegingDate" => "-",
"DeadLine" => "-"
]
];
}
if ($pdf->GetY() + 30 > $pdf->getPageHeight()) {
$pdf->AddPage();
$pdf->Image($headerImgPath, 0, 0, $pageWidth, $headerImgHeight, '', '', '', false, 300, '', false, false, 0);
$pdf->Image($footerImgPath, 0, 267, $pageWidth, $footerImgHeight, '', '', '', false, 300, '', false, false, 0);
$pdf->SetFont($titleFont, '', 8);
$pdf->SetTextColor(144, 144, 144);
$pdf->Text($pdf->GetX()+8, $pdf->GetY()+2, $qy_data['Name']);
$pdf->Ln(12);
}
$pdf->SetFillColor(95, 183, 255);
$pdf->SetTextColor($titleTextColor[0], $titleTextColor[1], $titleTextColor[2]);
$pdf->Rect($pdf->GetX(), $pdf->GetY(), $titleWidth, $titleHeight-2, 'F');
$pdf->SetFont($titleFont, 'B', 12);
$titleText = ' 企业资质(如高新技术企业、创新型/科技型中小企业)';
$pdf->Text(12, $pdf->GetY()+4, $titleText);
$pdf->Ln(12);
foreach ($data as $key => $val) {
if ($pdf->GetY() + 30 > $pdf->getPageHeight()) {
$pdf->AddPage();
$pdf->Image($headerImgPath, 0, 0, $pageWidth, $headerImgHeight, '', '', '', false, 300, '', false, false, 0);
$pdf->Image($footerImgPath, 0, 267, $pageWidth, $footerImgHeight, '', '', '', false, 300, '', false, false, 0);
$pdf->SetFont($titleFont, '', 8);
$pdf->SetTextColor(144, 144, 144);
$pdf->Text($pdf->GetX()+8, $pdf->GetY()+2, $qy_data['Name']);
$pdf->Ln(12);
}
$pdf->SetTextColor(0,0,0);
$pdf->SetFont($titleFont, '', 8);
$pdf->SetFillColor(244, 244, 244);
$pdf->Cell(30, 10, '资质名称', 1, 0, 'C', 1);
$pdf->SetFillColor(255, 255, 255);
$pdf->Cell(65, 10, $val['Name'], 1, 0, 'L', 1);
$pdf->SetFillColor(244, 244, 244);
$pdf->Cell(30, 10, '级别', 1, 0, 'C', 1);
$pdf->SetFillColor(255, 255, 255);
$pdf->Cell(65, 10, $val['Level'], 1, 1, 'L', 1);
$pdf->SetFillColor(244, 244, 244);
$pdf->Cell(30, 10, '来源', 1, 0, 'C', 1);
$pdf->SetFillColor(255, 255, 255);
$pdf->Cell(65, 10, $val['Source'], 1, 0, 'L', 1);
$pdf->SetFillColor(244, 244, 244);
$pdf->Cell(30, 10, '发布单位', 1, 0, 'C', 1);
$pdf->SetFillColor(255, 255, 255);
$pdf->Cell(65, 10, $val['PublishOffice'], 1, 1, 'L', 1);
$pdf->Ln(2);
}
$pdf->AddPage();
$pdf->Image($headerImgPath, 0, 0, $pageWidth, $headerImgHeight, '', '', '', false, 300, '', false, false, 0);
$pdf->Image($footerImgPath, 0, 267, $pageWidth, $footerImgHeight, '', '', '', false, 300, '', false, false, 0);
$pdf->SetFont($titleFont, '', 8);
$pdf->SetTextColor(144, 144, 144);
$pdf->Text($pdf->GetX()+8, $pdf->GetY()+2, $qy_data['Name']);
$pdf->Ln(12);
$pdf->SetFillColor($titleBackgroundColor[0], $titleBackgroundColor[1], $titleBackgroundColor[2]);
$pdf->SetTextColor($titleTextColor[0], $titleTextColor[1], $titleTextColor[2]);
$pdf->SetFont($titleFont, 'B', $titleFontSize);
$pdf->Rect(10, 25, $titleWidth, $titleHeight, 'F');
$titleText = '企业评测结果概览';
$pdf->Text(12, 29, $titleText);
$pdf->Ln();
$scoreImg = 'https://******.png';
$pdf->Image($scoreImg, 35, 45, 135, 45, '', '', 'C', false, 300, '', false, false, 0);
$zongScore = Question::with(['record'])
->where(['gp_id' => 1, 'pid' => $row['record_id'], 'state' => 0, 'record.test_log_id' => $row['id']])
->order('sort','asc')
->sum('record.result_value');
$pdf->SetTextColor(34, 84, 244);
$pdf->SetFont($titleFont, '', 19);
if($zongScore>99){
$pdf->Text(48, 49, $zongScore);
}elseif($zongScore<10){
$pdf->Text(53, 49, $zongScore);
}else{
$pdf->Text(50, 49, $zongScore);
}
$pdf->SetTextColor(50, 113, 229);
$pdf->SetFont($titleFont, '', 24);
if($row['score']>100){
$pdf->Text(92, 62, $row['score']);
}else{
$pdf->Text(96, 62, $row['score']);
}
$pdf->SetTextColor(98, 199, 184);
$pdf->SetFont($titleFont, '', 19);
if($row['score']-$zongScore>99){
$pdf->Text(131, 52, $row['score']-$zongScore);
}else{
$pdf->Text(133, 52, $row['score']-$zongScore);
}
$analysis = 'https://********.png';
$pdf->Image($analysis, 10, 100, $titleWidth, 52, '', '', 'C', false, 300, '', false, false, 0);
$pdf->SetTextColor(44,44,44);
$pdf->SetFont($titleFont, '', 12);
$zong = '本次报告测评结果分为【综合评汉分数】与【维度评测分数】两部分组成,总分为200分。在本次测评中,您的企业综合评测得分为X分,维度评测分数为Y分。您的综合评指标存在不足,上年度研发占比、上年度获得机构融资总额未满足,需有针对性地加强。维度评测得分<60分,专业化、精细化、特色化、创新力方面需有针对性地加强,经过专业辅导后可满足申报条件。如您的企业有申报需求,可在线咨询平台专家,专家会根据您报告得分的具体情况为您提供专业建议并制定申报辅导方案。';
$pdf->MultiCell(145, 0, $zong, 0, 'L', false, 1, 52, 103, true, 0, false, true, 0, 'T', false);
$pdf->SetFillColor($titleBackgroundColor[0], $titleBackgroundColor[1], $titleBackgroundColor[2]);
$pdf->SetTextColor($titleTextColor[0], $titleTextColor[1], $titleTextColor[2]);
$pdf->SetFont($titleFont, 'B', $titleFontSize);
$pdf->Rect(10, 166, $titleWidth, $titleHeight, 'F');
$titleText = '综合评测分数分析';
$pdf->Text(12, 170, $titleText);
$pdf->Ln(12);
$pdf->SetTextColor(0,0,0);
$pdf->SetFont($titleFont, '', 8);
$data = Question::with(['record'])
->where(['gp_id' => 1, 'pid' => $row['record_id'], 'state' => 0, 'record.test_log_id' => $row['id']])
->order('sort','asc')
->select();
usort($data, function($a, $b) {
if ($a['record']['result_value'] > 0 && $b['record']['result_value'] <= 0) {
return -1;
} elseif ($a['record']['result_value'] <= 0 && $b['record']['result_value'] > 0) {
return 1;
} else {
return 0;
}
});
$is_true = 0;
$is_false = 0;
foreach ($data as $key => $val) {
if($key < 6){
if ($pdf->GetY() + 35 > $pdf->getPageHeight()) {
$pdf->AddPage();
$pdf->Image($headerImgPath, 0, 0, $pageWidth, $headerImgHeight, '', '', '', false, 300, '', false, false, 0);
$pdf->Image($footerImgPath, 0, 267, $pageWidth, $footerImgHeight, '', '', '', false, 300, '', false, false, 0);
$pdf->SetFont($titleFont, '', 8);
$pdf->SetTextColor(144, 144, 144);
$pdf->Text($pdf->GetX()+8, $pdf->GetY()+2, $qy_data['Name']);
$pdf->Ln(12);
}
if($val['record']['result_value']>0 || ($val['record']['result_value']==0 && $val['record']['data'] === '')){
if($is_true == 0){
$pdf->Ln();
$pdf->SetFont($titleFont, 'B', 12);
$pdf->SetFillColor(95, 183, 255);
$pdf->SetTextColor($titleTextColor[0], $titleTextColor[1], $titleTextColor[2]);
$pdf->Rect($pdf->GetX(), $pdf->GetY()-6, $titleWidth, $titleHeight-2, 'F');
$pdf->Text($pdf->GetX(), $pdf->GetY()-2, ' 已满足条件分析');
$pdf->Ln(12);
$is_true = 1;
}
$pdf->SetTextColor(95, 188, 102);
$successImg = 'https://**********.png';
}else{
if($is_false == 0){
$pdf->Ln();
$pdf->SetFont($titleFont, 'B', 12);
$pdf->SetFillColor(95, 183, 255);
$pdf->SetTextColor($titleTextColor[0], $titleTextColor[1], $titleTextColor[2]);
$pdf->Rect($pdf->GetX(), $pdf->GetY()-6, $titleWidth, $titleHeight-2, 'F');
$pdf->Text($pdf->GetX(), $pdf->GetY()-2, '未满足条件分析');
$pdf->Ln(12);
$is_false = 1;
}
$pdf->SetTextColor(239, 56, 34);
$successImg = 'https://**********.png';
}
if ($pdf->GetY() + 35 > $pdf->getPageHeight()) {
$pdf->AddPage();
$pdf->Image($headerImgPath, 0, 0, $pageWidth, $headerImgHeight, '', '', '', false, 300, '', false, false, 0);
$pdf->Image($footerImgPath, 0, 267, $pageWidth, $footerImgHeight, '', '', '', false, 300, '', false, false, 0);
$pdf->SetFont($titleFont, '', 8);
$pdf->SetTextColor(144, 144, 144);
$pdf->Text($pdf->GetX()+8, $pdf->GetY()+2, $qy_data['Name']);
$pdf->Ln(12);
}
$pdf->SetFillColor(233, 233, 233);
$pdf->Cell(10, 10, '', ['LTB' => ['width' => 0.1, 'color' => [233, 233, 233]]],0,'L',1);
$pdf->SetFont($titleFont, '', 10);
$pdf->Cell($titleWidth-30, 10, $val['name'], ['LTRB' => ['width' => 0.1, 'color' => [233, 233, 233]]], 0, 'L', 1);
$pdf->SetTextColor(0, 0, 0);
$pdf->Cell(20, 10, '', ['LTRB' => ['width' => 0.1, 'color' => [233, 233, 233]]], 1, 'L', 1);
$pdf->Image($successImg, $pdf->GetX() + 3, $pdf->GetY()-8, 5);
$pdf->SetFillColor(255, 255, 255);
$pdf->SetTextColor(0, 140, 255);
if($key == 5 && $val['record']['data'] === null){
$content = '企业已满足1.近三年获得过省级科技奖励,并排名前三2.近三年获得国家级科技奖励,并在获奖单位中排名前五3.近两年研发费用总额均值在1000万元以上4.近两年新增股权融资总额(合格机构投资者实缴金额)达到6000万元以上4.近三年进入“创客中国”中小企业创新创业大赛全国500强企业#其中一项或多项,满足条件。';
$contentHeight = $pdf->GetStringHeight($tWidth + 130,$content);
$rowHeight = max(10, $contentHeight);
$pdf->Cell(25, $contentHeight, '【大师兄点评】', ['LTB' => ['width' => 0.1, 'color' => [233, 233, 233]]],0,'L',0);
$pdf->SetTextColor(144, 144, 144);
$pdf->MultiCell($tWidth + 135, $rowHeight, $content, ['TRB' => ['width' => 0.1, 'color' => array(233, 233, 233)]], 'L', 0, 1,'', '', true, 0, false, true, $rowHeight, 'M');
$pdf->Ln(2);
}elseif ($key == 5 && $val['record']['data'] === ''){
$content = '企业已满足1.近三年获得过省级科技奖励,并排名前三2.近三年获得国家级科技奖励,并在获奖单位中排名前五3.近两年研发费用总额均值在1000万元以上4.近两年新增股权融资总额(合格机构投资者实缴金额)达到6000万元以上4.近三年进入“创客中国”中小企业创新创业大赛全国500强企业#其中一项或多项,满足条件。';
$contentHeight = $pdf->GetStringHeight($tWidth + 130,$content);
$rowHeight = max(10, $contentHeight);
$pdf->Cell(25, $contentHeight, '【大师兄点评】', ['LTB' => ['width' => 0.1, 'color' => [233, 233, 233]]],0,'L',0);
$pdf->SetTextColor(144, 144, 144);
$pdf->MultiCell($tWidth + 135, $rowHeight, $content, ['TRB' => ['width' => 0.1, 'color' => array(233, 233, 233)]], 'L', 0, 1,'', '', true, 0, false, true, $rowHeight, 'M');
}else{
$content = \app\admin\model\question\Tips::where(['group_id' => $val['standard_group'],'result_value' => $val['record']['result_value']])->value('content');
$contentHeight = $pdf->GetStringHeight($tWidth + 130,$content);
$rowHeight = max(10, $contentHeight);
$pdf->Cell(25, $rowHeight, '【大师兄点评】', ['LTB' => ['width' => 0.1, 'color' => [233, 233, 233]]],0,'L',0);
$pdf->SetTextColor(144, 144, 144);
$pdf->MultiCell($tWidth + 135, $rowHeight, $content, ['TRB' => ['width' => 0.1, 'color' => array(233, 233, 233)]], 'L', 0, 1,'', '', true, 0, false, true, $rowHeight, 'M');
$pdf->Ln(2);
}
}
}
$pdf->SetFillColor($titleBackgroundColor[0], $titleBackgroundColor[1], $titleBackgroundColor[2]);
$pdf->SetTextColor($titleTextColor[0], $titleTextColor[1], $titleTextColor[2]);
$pdf->SetFont($titleFont, 'B', $titleFontSize);
$pdf->Rect($pdf->GetX(), $pdf->GetY()+4, $titleWidth, $titleHeight, 'F');
$titleText = '维度评测分数分析';
$pdf->Text($pdf->GetX()+2, $pdf->GetY()+7, $titleText);
$zScore = Question::with(['record'])
->where(['gp_id' => 2, 'pid' => $row['record_id'], 'state' => 0, 'record.test_log_id' => $row['id']])
->order('sort','asc')
->sum('record.result_value');
$jScore = Question::with(['record'])
->where(['gp_id' => 3, 'pid' => $row['record_id'], 'state' => 0, 'record.test_log_id' => $row['id']])
->order('sort','asc')
->sum('record.result_value');
$xScore = Question::with(['record'])
->where(['gp_id' => 4, 'pid' => $row['record_id'], 'state' => 0, 'record.test_log_id' => $row['id']])
->order('sort','asc')
->sum('record.result_value');
$tScore = Question::with(['record'])
->where(['gp_id' => 5, 'pid' => $row['record_id'], 'state' => 0, 'record.test_log_id' => $row['id']])
->order('sort','asc')
->sum('record.result_value');
$pdf->Ln();
$values = array($jScore,$zScore,$xScore,$tScore);
$graph = $this->createRadarGraph($values);
ob_start();
$graph->Stroke();
$imgData = ob_get_clean();
$pdf->Image('@' . $imgData, $pdf->GetX()+42, $pdf->GetY()+16, 100, 100, '', '', 'C', false, 300, '', false, false, 0);
$pdf->SetTextColor(0, 0, 0);
$pdf->SetFont($titleFont, 'B', 14);
$pdf->Text(95, $pdf->GetY()+10, '精细化');
$pdf->SetFont($titleFont, '', 10);
$pdf->Text(95, $pdf->GetY()+10, '评分:');
$pdf->SetTextColor(239, 56, 34);
$pdf->Text(106, $pdf->GetY(), $jScore);
$pdf->SetTextColor(0, 0, 0);
$pdf->SetFont($titleFont, 'B', 14);
$pdf->Text(45, $pdf->GetY()+38, '专业化');
$pdf->SetFont($titleFont, '', 10);
$pdf->Text(45, $pdf->GetY()+11, '评分:');
$pdf->SetTextColor(239, 56, 34);
$pdf->Text(56, $pdf->GetY(), $zScore);
$pdf->SetTextColor(0, 0, 0);
$pdf->SetFont($titleFont, 'B', 14);
$pdf->Text(145, $pdf->GetY()-11, '特色化');
$pdf->SetFont($titleFont, '', 10);
$pdf->Text(145, $pdf->GetY()+10, '评分:');
$pdf->SetTextColor(239, 56, 34);
$pdf->Text(156, $pdf->GetY(), $tScore);
$pdf->SetTextColor(0, 0, 0);
$pdf->SetFont($titleFont, 'B', 14);
$pdf->Text(95, $pdf->GetY()+40, '新颖化');
$pdf->SetFont($titleFont, '', 10);
$pdf->Text(95, $pdf->GetY()+10, '评分:');
$pdf->SetTextColor(239, 56, 34);
$pdf->Text(106, $pdf->GetY(), $xScore);
$pdf->Ln();
$pdf->SetFillColor(237, 237, 237);
$pdf->SetTextColor(0,0,0);
$pdf->SetFont($titleFont, '', 12);
$pdf->Rect($pdf->GetX(), $pdf->GetY()+4, $titleWidth, 20, 'F');
$titleText = '当前企业维度评分为';
$pdf->Text(45, $pdf->GetY()+8, $titleText);
$pdf->SetTextColor(239, 56, 34);
$pdf->SetFont($titleFont, '', 18);
$titleText = $zScore + $tScore + $xScore + $jScore;
$pdf->Text(84, $pdf->GetY()-2, $titleText);
$pdf->SetTextColor(0,0,0);
$pdf->SetFont($titleFont, '', 12);
$titleText = '分,评分高代表该维度指标最强,';
$pdf->Text(93, $pdf->GetY()+2, $titleText);
$titleText = '评分低代表该指标有待提高,详细分析见下方。';
$pdf->Text(55, $pdf->GetY()+8, $titleText);
$pdf->Ln();
$pdf->AddPage();
$pdf->Image($headerImgPath, 0, 0, $pageWidth, $headerImgHeight, '', '', '', false, 300, '', false, false, 0);
$pdf->Image($footerImgPath, 0, 267, $pageWidth, $footerImgHeight, '', '', '', false, 300, '', false, false, 0);
$pdf->SetFont($titleFont, '', 8);
$pdf->SetTextColor(144, 144, 144);
$pdf->Text($pdf->GetX()+8, $pdf->GetY()+2, $qy_data['Name']);
$pdf->Ln(12);
$data = Question::with(['record'])
->where(['gp_id' => ['in','2,3,4,5'], 'pid' => $row['record_id'], 'state' => 0, 'record.test_log_id' => $row['id']])
->order('sort','asc')
->select();
$wei = [
0 => ['name'=>'专业化','score' => 25,'gScore' => $zScore],
4 => ['name'=>'精细化','score' => 25,'gScore' => $jScore],
8 => ['name'=>'新颖化','score' => 35,'gScore' => $xScore],
12 => ['name'=>'特色化','score' => 15,'gScore' => $tScore],
];
$lastKey = count($data)-1;
foreach ($data as $key => $val){
if ($pdf->GetY() + 30 > $pdf->getPageHeight()) {
$pdf->AddPage();
$pdf->Image($headerImgPath, 0, 0, $pageWidth, $headerImgHeight, '', '', '', false, 300, '', false, false, 0);
$pdf->Image($footerImgPath, 0, 267, $pageWidth, $footerImgHeight, '', '', '', false, 300, '', false, false, 0);
$pdf->SetFont($titleFont, '', 8);
$pdf->SetTextColor(144, 144, 144);
$pdf->Text($pdf->GetX()+8, $pdf->GetY()+2, $qy_data['Name']);
$pdf->Ln(8);
}
if($key == 0 || $key == 4 || $key == 8 || $key == 12){
$pdf->Ln(2);
$pdf->SetFillColor(95, 183, 255);
$pdf->SetFont($titleFont, '', 12);
$pdf->SetTextColor($titleTextColor[0], $titleTextColor[1], $titleTextColor[2]);
$pdf->Rect($pdf->GetX(), $pdf->GetY(), $titleWidth, $titleHeight-2, 'F');
$pdf->Text($pdf->GetX()+4, $pdf->GetY()+4, $wei[$key]['name']);
$pdf->SetDrawColor(148, 172, 250);
$pdf->SetFillColor(255,255,255);
$width = 50;
$height = 30;
$pdf->RoundedRect(10, $pdf->GetY()+10, $width, $height, 2, '1111', 'DF');
$pdf->SetFont($titleFont, 'B', 32);
$pdf->SetTextColor(0,0,0);
if($wei[$key]['gScore']<=9){
$pdf->Text(30, $pdf->GetY()+15, $wei[$key]['gScore']);
}else{
$pdf->Text(28, $pdf->GetY()+15, $wei[$key]['gScore']);
}
$pdf->SetFont($titleFont, 'B', 12);
$pdf->SetTextColor(118, 118, 119);
$pdf->Text(24, $pdf->GetY()+15, '满分 '.$wei[$key]['score'] . ' 分');
$progressX = 80;
$progressY = $pdf->GetY()-5;
$progressWidth = 100;
$progressHeight = 8;
$cornerRadius = 2;
$progressColor = [71, 136, 255];
$progressPercentage = $wei[$key]['gScore'] / $wei[$key]['score'] * 100;
$actualProgressWidth = $progressWidth * ($progressPercentage / 100);
$pdf->SetFillColor(200, 200, 200);
$pdf->RoundedRect($progressX, $progressY, $progressWidth, $progressHeight, $cornerRadius, '1111', 'DF');
if($wei[$key]['gScore'] != 0){
$pdf->RoundedRect($progressX, $progressY, $actualProgressWidth, $progressHeight, $cornerRadius, '1111', 'DF','',$progressColor);
}
$textX = $progressX + $actualProgressWidth - 8;
$textY = $progressY + $progressHeight / 2 - 14;
$pdf->SetFont($titleFont, '', 16);
$pdf->SetTextColor(240, 74, 54);
$pdf->Text($textX, $textY, $wei[$key]['gScore'] . ' 分');
$pdf->SetFont($titleFont, '', 12);
$pdf->SetTextColor(164, 164, 164);
$pdf->Text($progressX - 12, $progressY+2, '0 分');
$pdf->Text($progressX+103, $progressY+2, $wei[$key]['score'] . ' 分');
$pdf->Ln(14);
}
$pdf->Ln(4);
$pdf->SetFillColor(233, 233, 233);
$pdf->Cell(5, 10, '', ['LTB' => ['width' => 0.1, 'color' => [233, 233, 233]]],0,'L',1);
$pdf->SetFont($titleFont, '', 10);
$pdf->SetTextColor(0, 0, 0);
$pdf->Cell($titleWidth-25, 10, $val['name'], ['LTRB' => ['width' => 0.1, 'color' => [233, 233, 233]]], 0, 'L', 1);
$pdf->Cell(20, 10, '得分:'.intval($val['record']['result_value']).'分', ['LTRB' => ['width' => 0.1, 'color' => [233, 233, 233]]], 1, 'L', 1);
if ($pdf->GetY() + 30 > $pdf->getPageHeight()) {
$pdf->AddPage();
$pdf->Image($headerImgPath, 0, 0, $pageWidth, $headerImgHeight, '', '', '', false, 300, '', false, false, 0);
$pdf->Image($footerImgPath, 0, 267, $pageWidth, $footerImgHeight, '', '', '', false, 300, '', false, false, 0);
$pdf->SetFont($titleFont, '', 8);
$pdf->SetTextColor(144, 144, 144);
$pdf->Text($pdf->GetX()+8, $pdf->GetY()+2, $qy_data['Name']);
$pdf->Ln(12);
}
$contentHeight = $pdf->GetStringHeight($tWidth + 130,$val['option_answer']);
$rowHeight = max(10, $contentHeight);
$pdf->SetTextColor(106, 192, 112);
$pdf->SetFont($titleFont, '', 10);
$pdf->Cell(2, $rowHeight, '', ['LTB' => ['width' => 0.1, 'color' => [233, 233, 233]]],0,'L',0);
$pdf->MultiCell($tWidth + 138, $rowHeight, '满分指标:'.$val['option_answer'], ['TB' => ['width' => 0.1, 'color' => array(233, 233, 233)]], 'L', 0, 0,'', '', true, 0, false, true, $rowHeight, 'M');
$pdf->Cell(20, $rowHeight, '满分:'.$val['option_score'].'分', ['TRB' => ['width' => 0.1, 'color' => [233, 233, 233]]],1,'L',0);
if ($pdf->GetY() + 30 > $pdf->getPageHeight()) {
$pdf->AddPage();
$pdf->Image($headerImgPath, 0, 0, $pageWidth, $headerImgHeight, '', '', '', false, 300, '', false, false, 0);
$pdf->Image($footerImgPath, 0, 267, $pageWidth, $footerImgHeight, '', '', '', false, 300, '', false, false, 0);
$pdf->SetFont($titleFont, '', 8);
$pdf->SetTextColor(144, 144, 144);
$pdf->Text($pdf->GetX()+8, $pdf->GetY()+2, $qy_data['Name']);
$pdf->Ln(12);
}
if($val['gp_id'] == 5 && $key == $lastKey){
if($tScore <= 4){
$result_value = 4;
}elseif($tScore > 4 && $tScore <= 10){
$result_value = 10;
}elseif($tScore > 10 && $tScore <= 15){
$result_value = 15;
}
$content = \app\admin\model\question\Tips::where(['group_id' => 'GP_5','result_value' => $result_value])->value('content');
$contentHeight = $pdf->GetStringHeight($tWidth + 130,$content);
$rowHeight = max(10, $contentHeight);
$pdf->SetTextColor(0, 140, 255);
$pdf->Cell(25, $rowHeight, '【大师兄建议】', ['LTB' => ['width' => 0.1, 'color' => [233, 233, 233]]],0,'L',0);
$pdf->SetTextColor(144, 144, 144);
$pdf->MultiCell($tWidth + 135, $rowHeight, $content, ['TRB' => ['width' => 0.1, 'color' => array(233, 233, 233)]], 'L', 0, 1,'', '', true, 0, false, true, $rowHeight, 'M');
}elseif($val['gp_id'] != 5){
$content = \app\admin\model\question\Tips::where(['group_id' => $val['standard_group'],'result_value' => $val['record']['result_value']])->value('content');
$contentHeight = $pdf->GetStringHeight($tWidth + 130,$content);
$rowHeight = max(10, $contentHeight);
$pdf->SetTextColor(0, 140, 255);
$pdf->Cell(25, $rowHeight, '【大师兄建议】', ['LTB' => ['width' => 0.1, 'color' => [233, 233, 233]]],0,'L',0);
$pdf->SetTextColor(144, 144, 144);
$pdf->MultiCell($tWidth + 135, $rowHeight, $content, ['TRB' => ['width' => 0.1, 'color' => array(233, 233, 233)]], 'L', 0, 1,'', '', true, 0, false, true, $rowHeight, 'M');
}
}
$pdf->Ln(17);
if ($pdf->GetY() + 30 > $pdf->getPageHeight()) {
$pdf->AddPage();
$pdf->Image($headerImgPath, 0, 0, $pageWidth, $headerImgHeight, '', '', '', false, 300, '', false, false, 0);
$pdf->Image($footerImgPath, 0, 267, $pageWidth, $footerImgHeight, '', '', '', false, 300, '', false, false, 0);
$pdf->SetFont($titleFont, '', 8);
$pdf->SetTextColor(144, 144, 144);
$pdf->Text($pdf->GetX()+8, $pdf->GetY()+2, $qy_data['Name']);
$pdf->Ln(12);
}
$pdf->SetTextColor(125, 125, 125);
$content = '更详尽的专精特新企业分析报告,请联系平台客服400-123-123,或直接进入《专精特新专区》在线咨询,上千专家在线为您解读报告!';
$pdf->MultiCell(145, 30, $content, 0, 'L');
$imgPath = 'https://***********.png';
$pdf->Image($imgPath, 170, $pdf->GetY()-40, 30, 30, '', '', 'C', false, 300, '', false, false, 0);
$file = ROOT_PATH.'/public/uploads/'. $qy_data['report_number'] .'.pdf';
$pdf->Output($file, 'FI');
上几个效果图