duannian7116 2016-10-22 08:35
浏览 44

如何使用PHP数组创建PDF文件

I trying to create PDF using FPDF by PHP. Here is my code.

require 'fpdf.php';
$pdf= new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial', "", 18);
$pdf->Ln();
$fruits=["apple", "Strawberry", "Banana"];
$animals=['Lion', 'Camel', 'Dog'];
$numbers=[1,2,3];

$i=0;
while($i<count($array))
{
    $pdf->Cell(5, 5, $fruits[$i]);

    $pdf->Cell(35, 35, $animals[$i]);
$pdf->Cell(35, 35, $numbers[$i]);
    $i++;
}
$pdf->output();

I am getting the output in this way

apple Strawberry Banana
Lion Camel Dog
1    2    3

But I am looking the output like with table format. I Have tried multiple ways using html tags like
, and regex ' '. But I didn't get output. I am getting the output in the above format only.

apple         Lion   1
Strawberry    Camel  2
Banana        Dog    3

Thanks in advance and welcome with all new ideas. Thanks You

  • 写回答

2条回答 默认 最新

  • dongshao6591 2016-11-03 13:50
    关注

    First, $array is undefined in the condition of your while statement.

    Your table is disarranged because you are adding cells with different heights.

    This should work:

    $i = 0;
    while ($i < count($fruits))
    {
        $pdf->Cell(35, 8, $fruits[$i]);
        $pdf->Cell(35, 8, $animals[$i]);
        $pdf->Cell(35, 8, $numbers[$i]);
        // Insert a line break at the end of each row.
        $pdf->Ln();
        $i++;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)