我有一个动态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列组成:产品引用、名称、价格和单元。我需要名称列比其他列更宽,或者如果可能的话(自动调整)到产品名称。
发布于 2016-11-22 16:24:29
Cell方法中的第一个参数是宽度。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();
}
}https://stackoverflow.com/questions/40746564
复制相似问题