【问题标题】:How do you make a table like this with FPDF using PHP?你如何使用 PHP 用 FPDF 制作这样的表格?
【发布时间】:2012-11-04 14:49:01
【问题描述】:

如何使用 PHP 用 FPDF 制作这样的表格?

我似乎无法弄清楚如何使用 $this->Cell 来做到这一点。

【问题讨论】:

  • 我愿意使用 TCPDF,如果可以的话

标签: php pdf-generation tcpdf fpdf


【解决方案1】:

我想我找到了其他解决方案,这是我不需要空单元格的解决方案。

$pdf->Cell(40,18,'Words Here', 1,0, 'C');
$x = $pdf->GetX();
$pdf->Cell(40,6,'Words Here', 1,0);
$pdf->Cell(40,6,'Words Here', 1,1);
$pdf->SetX($x);
$pdf->Cell(40,6,'[x] abc', 1,0);
$pdf->Cell(40,6,'[x] Checkbox 1', 1,1);
$pdf->SetX($x);
$pdf->Cell(40,6,'[x] def', 1,0);
$pdf->Cell(40,6,'[x] Checkbox 1', 1,1);

结果如下:

【讨论】:

    【解决方案2】:

    谢谢,有帮助,这对我有用:

    $this->Cell(40,5,' ','LTR',0,'L',0);   // empty cell with left,top, and right borders
    $this->Cell(50,5,'111 Here',1,0,'L',0);
    $this->Cell(50,5,'222 Here',1,0,'L',0);
    
                    $this->Ln();
    
    $this->Cell(40,5,'Solid Here','LR',0,'C',0);  // cell with left and right borders
    $this->Cell(50,5,'[ o ] che1','LR',0,'L',0);
    $this->Cell(50,5,'[ x ] che2','LR',0,'L',0);
    
                    $this->Ln();
    
    $this->Cell(40,5,'','LBR',0,'L',0);   // empty cell with left,bottom, and right borders
    $this->Cell(50,5,'[ x ] def3','LRB',0,'L',0);
    $this->Cell(50,5,'[ o ] def4','LRB',0,'L',0);
    
                    $this->Ln();
                    $this->Ln();
                    $this->Ln();
    

    【讨论】:

      【解决方案3】:

      FPDF 无法识别 rowspancolspan。这是您可以尝试的解决方法,使用空单元格和Cellborder 属性。

      $pdf->Cell(40,5,' ','LTR',0,'L',0);   // empty cell with left,top, and right borders
      $pdf->Cell(50,5,'Words Here',1,0,'L',0);
      $pdf->Cell(50,5,'Words Here',1,0,'L',0);
      $pdf->Cell(40,5,'Words Here','LR',1,'C',0);  // cell with left and right borders
      $pdf->Cell(50,5,'[ x ] abc',1,0,'L',0);
      $pdf->Cell(50,5,'[ x ] checkbox1',1,0,'L',0);
      $pdf->Cell(40,5,'','LBR',1,'L',0);   // empty cell with left,bottom, and right borders
      $pdf->Cell(50,5,'[ x ] def',1,0,'L',0);
      $pdf->Cell(50,5,'[ x ] checkbox2',1,0,'L',0);
      

      结果将是 -

      【讨论】:

      • 单元格函数不包裹单元格的内容,如果内容长度超过单元格的宽度,它会流走。如果你有地址并使用单元格显示会产生丑陋的影响,那么它会从页面上跑掉。你知道如何解决这个问题吗?我会使用 MultiCell 吗?
      • 这行得通,除了换行符在错误的位置,这意味着该行应该停止并转到新行,这是错误的。这由第 5 个值确定,其中 1 为真(下一个单元格开始新行),0 为假。另一种表述方式是,当第 5 个值为 1 时,该单元格是行尾,因此上述代码中的第 3 行应为 $pdf->Cell(50,5,'Words Here',1,1 ,'L',0);
      猜你喜欢
      • 2023-01-20
      • 1970-01-01
      • 1970-01-01
      • 2013-07-12
      • 2015-07-07
      • 2018-02-07
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      相关资源
      最近更新 更多