dsbiw2911188 2012-10-26 06:59
浏览 57
已采纳

避免重复fpdf单元格

here is a screenshot which can explain you more clearly about how my everysecond cell is duplicating with the first one 1I am new to PHP and I was trying to make a pdf from fpdf but the difficulty is that I wanted to align two cell beside each other, but cells are duplicating beside each other. Here's my code:

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

    }
  • 写回答

1条回答 默认 最新

  • douba1498 2012-10-29 07:05
    关注

    you may try the below modified version of your code..

    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
    
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 速帮,学校需要在外上班没空
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改
  • ¥15 Windows 系统cmd后提示“加载用户设置时遇到错误”
  • ¥50 vue router 动态路由问题
  • ¥15 关于#.net#的问题:End Function
  • ¥15 无法import pycausal
  • ¥15 VS2022创建MVC framework提示:预安装的程序包具有对缺少的注册表值的引用
  • ¥15 weditor无法连接模拟器Local server not started, start with?
  • ¥20 6-3 String类定义