php - 避免 fpdf 单元格中的重复项

标签 php alignment cell fpdf

这是一张截图,可以更清楚地向您解释我的每一个单元格如何与第一个单元格复制 1我是 PHP 的新手,我试图从 fpdf 制作一个 pdf,但困难在于我想将两个单元格彼此对齐,但单元格彼此复制。 这是我的代码:

require("library/fpdf/fpdf.php");
  class pdf extends fpdf {

        enter code here

       function Footer() {

        enter code here

    //Position at 1.5 cm from bottom
        $this->SetY(-15);
        //Arial italic 8
        $this->SetFont('Arial','I',8);
        //Page number
        $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');

         }
     }
      $ctr=0;
     $pdf = new pdf('P','mm','A4');
     $pdf->AliasNbPages();
     $pdf->AddPage();
     $pdf->SetMargins(10,10,10);
     $pdf->SetXY(5,5);

                while ($lbl = mysql_fetch_assoc($get))
          {
                    $ctr++;
                    $pdf->SetFont('Arial','B',8);{
            $pdf->Cell(85,6,$lbl["hotelname"],1,0,'L');}
                    $pdf->SetFont('Arial','B',8);{
                    $pdf->Cell(85,6,$lbl["hotelname"],1,1,'L');}
                    $pdf->SetFont('Arial','',8);{
            $pdf->Cell(85,6,"Haji No-".$lbl["hajino"]."Ctr-"." ".$ctr,1,0,'L');
            $pdf->Cell(85,6,"Haji No-".$lbl["hajino"]."Ctr-"." ".$ctr,1,1,'L');
                    }
            $pdf->Cell(85,6,$lbl["suffix"]." ". $lbl["surname"]." ". $lbl["name"]." ". $lbl["midname"],1,0,'L');
            $pdf->Cell(85,6,$lbl["suffix"]." ". $lbl["surname"]." ". $lbl["name"]." ". $lbl["midname"],1,1,'L');

                    $pdf->SetFont('Arial','B',8);{
            $pdf->Cell(85,6,"Room No - ". $lbl["roomno"]." "." "." "." "." "." "." ". "Bus No- ".$lbl["busname"],1,0,'L');
                    $pdf->Cell(85,6,"Room No - ". $lbl["roomno"]." "." "." "." "." "." "." ". "Bus No- ".$lbl["busname"],1,1,'L');
                    $pdf->Ln(10);
                    }




              }

            $pdf->Output('Hotel_label.pdf','D');


      } // Submit Tag Close

    }

最佳答案

您可以尝试以下修改后的代码版本..

require("library/fpdf/fpdf.php");
  class pdf extends fpdf {
       // enter code here

       function Footer() {
       // enter code here

    //Position at 1.5 cm from bottom
        $this->SetY(-15);
        //Arial italic 8
        $this->SetFont('Arial','I',8);
        //Page number
        $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');

         }
     }
      $ctr=0;

      $yheight=5;  //assign value for y-axis

     $pdf = new pdf('P','mm','A4');
     $pdf->AliasNbPages();
     $pdf->AddPage();
     $pdf->SetMargins(10,10,10);
     $pdf->SetXY(10,$yheight);


$loopvariable=1; //to check page break

$side=0;//to check left or right record placement

                while ($lbl = mysql_fetch_assoc($get))
          {
                    $ctr++;
                    if($side==0){                   
                    $pdf->SetFont('Arial','B',8);{
            $pdf->Cell(85,6,$lbl["hotelname"],1,1,'L');         
            $pdf->Cell(85,6,"Haji No-".$lbl["hajino"]."Ctr1-"." ".$ctr,1,1,'L');            
            $pdf->Cell(85,6,$lbl["suffix"]." ". $lbl["surname"]." ". $lbl["name"]." ". $lbl["midname"],1,1,'L');
            $pdf->Cell(85,6,"Room No - ". $lbl["roomno"]." "." "." "." "." "." "." ". "Bus No- ".$lbl["busname"],1,1,'L');
            $pdf->Ln(10);
                     }

                    $side++;

                    }else{



                         $pdf->SetFont('Arial','B',8);{
                              $pdf->SetXY(100,$yheight);
            $pdf->Cell(85,6,$lbl["hotelname"],1,1,'L');  
                              $pdf->SetXY(100,$yheight+6);
            $pdf->Cell(85,6,"Haji No-".$lbl["hajino"]."Ctr2-"." ".$ctr,1,1,'L');
                         $pdf->SetXY(100,$yheight+12);
            $pdf->Cell(85,6,$lbl["suffix"]." ". $lbl["surname"]." ". $lbl["name"]." ". $lbl["midname"],1,1,'L');
             $pdf->SetXY(100,$yheight+18);
            $pdf->Cell(85,6,"Room No - ". $lbl["roomno"]." "." "." "." "." "." "." ". "Bus No- ".$lbl["busname"],1,1,'L');
            $pdf->Ln(10);
                    }
                    $side--;        
                    $yheight+=34;
                if($loopvariable%16==0){$yheight=10;}//reset the y-axis value after every 16 records i.e. after every page break

                    }


$loopvariable++;

              }

            $pdf->Output('Hotel_label.pdf','D');



      } // Submit Tag Close

    }

关于php - 避免 fpdf 单元格中的重复项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13082251/

相关文章:

html - 是否有响应式垂直显示 : flex?(无表格/无 JS)

java - 有没有办法使用 POI Api 将图像添加到单元格?

excel - VBA 宏 Excel : How to read a Unicode character from Excel cell

vb.net - 在 datagridview vb.NET 中分割单元格。那可能吗?

php - Wordpress 中的前端媒体上传

php - php中while循环内的SQL查询

homebrew - 停止 "php-fpm"( Homebrew 安装)Mac OSX 10.8.2

php - PHP 中的最终抽象类?

android - 将微调器值右对齐而不是左对齐

Java BoxLayout 对齐问题