[英]Change width of one Column in Table using FPDF
我有一个动态PHP表,该表通过FPDF生成为PDF。
如何使“名称”列比其他列宽?
class PDF extends FPDF {
function Header() {
$this->Image('quote-header.png');
$this->Ln(2);
}
function Footer() {
$this->Image('quote-footer.png');
}
function LoadData($file) {
$lines = file($file);
$data = array();
foreach($lines as $line)
$data[] = explode(';', trim($line));
return $data;
}
function BasicTable($header, $data) {
foreach($header as $col)
$this->Cell(40, 7, $col, 1);
$this->Ln();
foreach($data as $row) {
foreach($row as $col)
$this->Cell(40, 6, $col, 1);
$this->Ln();
}
}
}
$header = array('Product Reference', 'Name', '('. $pound_sign .') Price (excl. VAT)', 'Unit');
我相信这是生成表的唯一代码吗?
任何帮助都是很棒的。 这是针对我工作的公司的产品报价系统,如果不解决此列宽问题,我将无法进一步进行。
该表由4列组成:产品参考,名称,价格和单位。 我需要“名称”列比其他列宽,或者在可能的情况下(自动调整)为“产品名称”。
Cell
方法中的第一个参数是width。 http://www.fpdf.org/en/doc/cell.htm
尝试将此尺寸增加一倍。
function BasicTable($header, $data) {
$nameIndex = array_search ( 'Name' , $header );
foreach($header as $key => $col) {
$width = ($key == $nameIndex) ? 80 : 40;
$this->Cell($width, 7, $col, 1);
}
$this->Ln();
// This assumes that $row is an int indexed array
// E.G looks like array(0 => 'some Product Reference ', 1 => 'Some Name' , 2 =>'Some Price', 3 => 'Some Unit')
foreach($data as $row) {
foreach($row as $key => $col) {
$width = ($key == $nameIndex) ? 80 : 40;
$this->Cell($width, 6, $col, 1);
}
$this->Ln();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.