php 如何在标题中居中图像 (TCPD)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5885713/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to center image in header (TCPDF)
提问by JohnWilks
I have the code below and I am guessing what is the center of the page by eye. How would I center the image the proper way?
我有下面的代码,我在猜测页面的中心是什么。我将如何以正确的方式将图像居中?
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);
}
}
Thanks
谢谢
回答by benske
This should work:
这应该有效:
// 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);
You can find more information in the API: http://www.tcpdf.org/doc/code/classTCPDF.html#a714c2bee7d6b39d4d6d304540c761352
您可以在 API 中找到更多信息:http: //www.tcpdf.org/doc/code/classTCPDF.html#a714c2bee7d6b39d4d6d304540c761352
回答by fdehanne
You have a param $palign
in Image()
你有一个PARAM$palign
在Image()
(string) Allows to center or align the image on the current line. Possible values are:
- L : left align
- C : center
- R : right align
- empty string : left for LTR or right for RTL
(字符串)允许在当前行上居中或对齐图像。可能的值为:
- L : 左对齐
- C : 中心
- R : 右对齐
- 空字符串:左为 LTR 或右为 RTL
With your image :
用你的形象:
$this->Image($image_file, 90, 5, 40, '', 'PNG', '', 'T', false, 300, 'C', false, false, 0, false, false, false);
回答by user757547
In TCPDF, you can use a HTML tag + Style in order to center a text/image.
在 TCPDF 中,您可以使用 HTML 标签 + 样式来居中文本/图像。
回答by MudMan23
You can try to use the HTML function in TCPDF. It's very simple: you create HTML like usual, and convert it into PDF.
您可以尝试使用 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
?>