【问题标题】:Avoiding duplicates in fpdf cells避免 fpdf 单元格中的重复
【发布时间】:2012-10-16 10:38:08
【问题描述】:

这是一个屏幕截图,可以更清楚地向您解释我的第二个单元格如何与第一个单元格重复 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

    }

【问题讨论】:

  • 对齐和复制是什么意思..我不清楚你想要达到什么目的..??还有check this如果有帮助的话..
  • 感谢您的回复,但正如您所见,我已将其对齐,但是当触发 da 查询时,第二个单元格与第一个单元格重复
  • 我怎样才能附加一个pdf文件???它可以更好地解释你
  • 我附上了我的 pdf 文件的截图,希望它可以向你解释
  • 您可以在屏幕截图中看到“hajino”,这表明您的单元格数据正在复制 n 请帮助我在 116 旁边打印下一个串行装置 117

标签: php alignment cell fpdf


【解决方案1】:

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

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

    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-01
    • 2017-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-06
    • 1970-01-01
    相关资源
    最近更新 更多