我已经搜索了很多这个解决方案,但没有运气,因为tcpdf的文档很差,所以我什么都没找到,我需要的是使用tcpdf作为pdf的铭牌打印,蚂蚁模板很简单就像图像一样
但问题是我无法正确旋转顶部。这是我的代码
$obj_pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$obj_pdf->AddPage('L' , 'A5');
$obj_pdf->StartTransform();
$obj_pdf->Rotate(-180);
$obj_pdf->image($logo1, 165 , 65, 0, 90, "PNG", "" , "M", true);
$obj_pdf->image($logo2, 0 , 65, 0, 90, "PNG", "" , "R", true);
$name = $functional_user->first_name .' '. $functional_user->last_name ;
$obj_pdf->SetTopMargin(-120);
$obj_pdf->SetLeftMargin(10);
$obj_pdf->setCellPaddings(0,0,0,0);
$tbl = '<br> <div class= "rotate" style="transform: rotate(180deg);">
<table cellpadding="2" >
<tr>
<td><h1 style = "font-size: 40px; line-height: 1.3">'.$name.' </h1>
<br><br><span style="font-size: 13px">
'.$org_logo_text.' </span>
</td>
</tr>
</table>
</div>';
$obj_pdf->writeHTML($tbl, true, false, false, false, '');
$obj_pdf->StopTransform();
$obj_pdf->SetTopMargin(78);
$obj_pdf->image($logo1, 10 , 70, 40, 20, "PNG", "" , "M", true);
$obj_pdf->image($logo2, 165 , 70, 40, 20, "PNG", "" , "R", true);
$name = $functional_user->first_name .' '. $functional_user->last_name ;
$obj_pdf->SetTopMargin(100);
$obj_pdf->SetLeftMargin(10);
$obj_pdf->setCellPaddings(0,0,0,0);
$tbl = '<br>
<table cellpadding="2" >
<tr>
<td><h1 style = "font-size: 40px; line-height: 1.3">'.$name.' </h1>
<br><br><span style="font-size: 13px">
'.$org_logo_text.' </span>
</td>
</tr>
</table>';
$obj_pdf->writeHTML($tbl, true, false, false, false, '');
$obj_pdf->lastPage();
$obj_pdf->Output('/tmp/Nameplate_' . $i . '.pdf', 'F');
$obj_pdf->Close();
有人能帮帮我吗?
答案 0 :(得分:0)
嗯,我自己解决了这个问题,我做错了就是使用rotate($ angle)函数。它确实旋转了部分,但它将中心点作为(0,0)或左上角并且因此在旋转之后整个部分位于pdf页面之外。所以最后我使用rotate($ angle,$ px,$ py)函数,其中px和py将从相应的轴推出该部分并放置所需的位置。这是我的代码
$obj_pdf->StartTransform();
$angle= 180;
$px= 105;
$py= 36;
$obj_pdf->Rotate($angle, $px, $py);
$obj_pdf->image($company_logo, 10 , 0, 40, 20, "PNG", "" , "M", true);
$obj_pdf->image($organization_logo, 165 , 0, 40, 20, "PNG", "" , "R", true);
$name = $functional_user->first_name .' '. $functional_user->last_name ;
$obj_pdf->SetTopMargin(27);
$obj_pdf->SetLeftMargin(10);
$fz = "35px";
if( strlen( $name )> 20) $fz = "40px";
else if( strlen($name)> 18 ) $fz = "33px";
$tbl = '<br><table cellpadding="1" >
<tr>
<td><h1 style = "font-size: '.$fz.'; line-height: 1.3">'.$name.' </h1>
<br><br><span style="font-size: 13px">
'.$org_logo_text.' </span>
</td>
</tr>
</table>';
$obj_pdf->writeHTML($tbl, true, false, false, false, '');
$obj_pdf->StopTransform();