【问题标题】:Why my table doesn't fit in the PDF output?为什么我的表格不适合 PDF 输出?
【发布时间】:2011-06-06 02:32:48
【问题描述】:

我正在使用FPDF(从 PHP 生成 PDF)。我想在表格标题中显示我的数组中的所有项目,但只显示了一些,比如列表太大而无法容纳,但格式不正确。我还不明白如何移动表格标题的尺寸。

这是我的代码:

<?php
require('fpdf.php');

class PDF extends FPDF
{
//Load data
function LoadData($file)
{
//Read file lines
$lines=file($file);
$data=array();
foreach($lines as $line)
    $data[]=explode(';',chop($line));
return $data;
    }

    //Colored table
    function FancyTable($header,$data)
    {
//Colors, line width and bold font
$this->SetFillColor(255,0,0);
$this->SetTextColor(255);
$this->SetDrawColor(128,0,0);
$this->SetLineWidth(.3);
$this->SetFont('','B');
//Header
$w=array(40,35,40,45);
for($i=0;$i<count($header);$i++)
    $this->Cell($w[$i],7,$header[$i],1,0,'C',true);
$this->Ln();


$this->Cell(array_sum($w),0,'','T');
    }
     }

     $pdf = new PDF('L', 'mm', 'A4');
     //Column titles
     $header=array('Name','Surname','Date','Start','Br Start','Br End','Start','End','Centre');
     //Data loading
     $data=$pdf->LoadData('countries.txt');
    $pdf->SetFont('Arial','',12);
    $pdf->AddPage();
    $pdf->FancyTable($header,$data);
     $pdf->Output();
       ?>

【问题讨论】:

    标签: php pdf-generation fpdf


    【解决方案1】:

    在您的代码中:

    $w=array(40,35,40,45);
    for($i=0;$i<count($header);$i++)
    

    如果 count($header) > 4 那么你就有麻烦了......正如我在你的截图中看到的那样。 对于未定义的值,您将 0 作为第一个参数......这意味着全宽。

    PS:打开错误报告以查看您的错误,确保 php 会抛出它们。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-03
      • 2011-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-26
      相关资源
      最近更新 更多