【问题标题】:FPDF print MultiCell() adjacentlyFPDF 相邻打印 MultiCell()
【发布时间】:2012-11-13 14:29:51
【问题描述】:

我四处搜索,发现这个问题很常见,但我似乎找不到正确而直接的答案。我正在使用 FPDF,我想使用 MultiCell() 生成表格,因为我需要它的换行属性。尝试过 Cell() 但它无法读取换行符。

$col1="PILOT REMARKS\n\n";
$pdf->MultiCell(189, 10, $col1, 1, 1);
$col2="Pilot's Name and Signature\n".$name;
$pdf->MultiCell(63, 10, $col2, 1);
$pdf->Ln(0);
$col3="Date Prepared\n".$date;
$pdf->MultiCell(63, 10, $col3, 1);

但我无法正确生成它,因为 MultiCell() 会堆叠结果。如何以最简单易行的方式实现 MultiCell() 彼此相邻打印?

找到了这个similar question,但它没有提供明确的答案。任何帮助将不胜感激。提前致谢。

【问题讨论】:

    标签: fpdf


    【解决方案1】:

    只需添加到Danny's answer。我喜欢保存每列的宽度,然后在执行 SetXY 方法时使用它。

    例子:

    $x = $this->x;
    $y = $this->y;
    $push_right = 0;
    
    $this->MultiCell($w = 100,3,"Column\r\nNumber 1",1,'C',1);
    
    $push_right += $w;
    $this->SetXY($x + $push_right, $y);
    
    $this->MultiCell($w = 60,3,"Column\r\nNumber 2",1,'C',1);
    
    $push_right += $w;
    $this->SetXY($x + $push_right, $y);
    
    $this->MultiCell(0,3,"Column 3\r\nFilling in the Rest",1,'C',1);
    

    【讨论】:

      【解决方案2】:

      使用$pdf->Ln(10); $pdf->cell();

      例子:

      $pdf->cell(100,10,"your content");
      $pdf->Ln(10);
      

      【讨论】:

        【解决方案3】:

        您可以使用 SetXY(x,y) 函数在 pdf 中设置光标。

                  $pdf->SetXY(x,y);
        

        设置光标以打印pdf格式的数据

        其中x是x轴值,y是y轴值

        【讨论】:

          【解决方案4】:

          尝试存储 X 和 Y 坐标,然后在写入后设置它们

          $x = $pdf->GetX();
          $y = $pdf->GetY();
          
          $col1="PILOT REMARKS\n\n";
          $pdf->MultiCell(189, 10, $col1, 1, 1);
          
          $pdf->SetXY($x + 189, $y);
          
          $col2="Pilot's Name and Signature\n".$name;
          $pdf->MultiCell(63, 10, $col2, 1);
          $pdf->Ln(0);
          $col3="Date Prepared\n".$date;
          $pdf->MultiCell(63, 10, $col3, 1);
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2013-12-29
            • 2013-03-01
            • 1970-01-01
            • 2010-11-28
            • 2013-04-15
            • 1970-01-01
            相关资源
            最近更新 更多