Php 如何在页眉中居中显示图像(TCPDF)
我有下面的代码,我用眼睛猜测页面的中心是什么。如何以正确的方式居中图像Php 如何在页眉中居中显示图像(TCPDF),php,tcpdf,Php,Tcpdf,我有下面的代码,我用眼睛猜测页面的中心是什么。如何以正确的方式居中图像 class MYPDF extends TCPDF { //Page header public function Header() { // Logo $image_file = K_PATH_IMAGES.'logo.png'; $this->Image($image_file, 90,
class MYPDF extends TCPDF {
//Page header
public function Header() {
// Logo
$image_file = K_PATH_IMAGES.'logo.png';
$this->Image($image_file, 90, 5, 40, '', 'PNG', '', 'T', false, 300, '', false, false, 0, false, false, false);
$style = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(39, 137, 199));
$this->Line($this->getPageWidth()-PDF_MARGIN_RIGHT, 25, PDF_MARGIN_LEFT, 25, $style);
}
}
感谢TCPDF中的HTML标记+样式,您可以使用HTML标记+样式将文本/图像居中。您可以尝试使用TCPDF中的HTML功能。它非常简单:您可以像往常一样创建HTML,然后将其转换为PDF
<?php
$html = '<h2>List of Expediton</h2> <!-- Title -->
<table border="1" cellspacing="3" cellpadding="4">
<tr>
<th align="left">Title</th> <!-- head of column name -->
<th align="center">Title</th> <!-- head of column name -->
<th align="right">Title</th> <!-- head of column name -->
</tr>
<tr>
<td>Example</td>
<td>Example</td>
<td>Example</td>
</tr>
</table>
';
$pdf->writeHTML($html, true, false, true, false, ''); //function to convert from HTML
?>
这应该可以:
// Image($file, $x='', $y='', $w=0, $h=0, $type='', $link='', $align='', $resize=false, $dpi=300, $palign='', $ismask=false, $imgmask=false, $border=0, $fitbox=false, $hidden=false, $fitonpage=false)
$this->Image($image_file, 'C', 6, '', '', 'JPG', false, 'C', false, 300, 'C', false, false, 0, false, false, false);
您可以在API中找到更多信息:您在API中有一个param
$paign
(字符串)允许在当前行上居中或对齐图像。可能的值为:
- L:左对齐
- C:中心
- R:右对齐
- 空字符串:左表示LTR,右表示RTL
$this->Image($image_file, 90, 5, 40, '', 'PNG', '', 'T', false, 300, 'C', false, false, 0, false, false, false);