Cell Starts In The New Page using SetXY() in FPDF PHP
<p>I'm trying to generate this kind of pdf and in the first page everything is ok.</p>

<p><img src="https://i.stack.imgur.com/2Bj18.png" alt="enter image description here"></p>

<p>But when I loop more then 23 times it looks the <code>Cell()</code> starts in the new page when page breaks.</p>

<p><img src="https://i.stack.imgur.com/Y538R.png" alt="enter image description here"></p>

<p>I want this Cell() to display like in first page.</p>

<p>Here is my code:</p>

<pre><code>class PDF extends FPDF {
    public $hPosX;
    public $hPosY;
    function FancyTable() {
        $this-&gt;SetFillColor(255,0,0);
        $this-&gt;SetTextColor(255,0,0);
        $this-&gt;SetDrawColor(128,0,0);
        $this-&gt;SetLineWidth(.3);
        $this-&gt;SetFont('','B');

        $this-&gt;headerTable();
     }

    public function headerTable(){
        $this-&gt;hPosX = 15;
        $this-&gt;hPosY = 3;
        $this-&gt;SetFillColor(255,0,0);
        $this-&gt;SetTextColor(255);
        $this-&gt;SetDrawColor(128,0,0);
        $this-&gt;SetLineWidth(.3);
        $this-&gt;SetFont('','B');
        for($i=0; $i&lt;30;$i++){
            if($this-&gt;GetX() &gt; 160){
                $this-&gt;hPosX  = 15;
                $this-&gt;hPosY  += 35; 
            }

            $this-&gt;SetXY($this-&gt;hPosX,$this-&gt;hPosY);
            $this-&gt;Cell(50,5,'Header'.$i,1,0,'L',true); 

            $this-&gt;hPosX += 55;
        }
    }
}




$pdf = new PDF();
$pdf-&gt;SetTopMargin(10);
$pdf-&gt;SetFont('Arial','',14);
$pdf-&gt;AddPage();
$pdf-&gt;FancyTable();
$pdf-&gt;Output();
</code></pre>

<p></p>

<p>Any solution will be highly appreciated.</p>