如何将图像置于标题中心(TCPDF)

时间:2011-05-04 15:15:14

标签: php tcpdf

我有下面的代码,我猜是眼睛的中心是什么。我如何以正确的方式将图像居中?

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);


        }
}

由于

4 个答案:

答案 0 :(得分:8)

这应该有效:

// 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中找到更多信息:http://www.tcpdf.org/doc/code/classTCPDF.html#a714c2bee7d6b39d4d6d304540c761352

答案 1 :(得分:5)

Image()

中有一个参数$palign
  

(字符串)允许在当前行上居中或对齐图像。可能的值有:

     
      
  • L:左对齐
  •   
  • C:中心
  •   
  • R:右对齐
  •   
  • 空字符串:左边是LTR,右边是RTL
  •   

用你的形象:

$this->Image($image_file, 90, 5, 40, '', 'PNG', '', 'T', false, 300, 'C', false, false, 0, false, false, false);

答案 2 :(得分:0)

在TCPDF中,您可以使用HTML标记+样式来居中文本/图像。

答案 3 :(得分:0)

我想你可以尝试在TCPDF中使用HTML功能,非常简单,就像你创建通常的html而不是PDF格式

<?
$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>Exemple</td>
        <td>Exemple</td>
        <td>Exemple</td>
    </tr>

</table>


$pdf->writeHTML($html, true, false, true, false, ''); //function for convert to HTML
?>
相关问题