Search code examples
phpfpdf

FPDF mssql array, image in cell pagebreak error


I'm trying to display 4 images per page with fpdf. I'm using cell and GetX and GetY to order, this works find for me, but when a new page is created always the first cell is empty, it hapens in all the pages, just display fine with the first one page. please help me! this is my code:

class PDF extends FPDF {
}
$pdf = new PDF('P','mm','Letter');
$pdf->SetFont('Times','',12);
$pdf->AddPage();
$con = mssql_connect(DB_HOST3, DB_USER3, DB_PASS3, DB_NAME3);
mssql_select_db("SBO_Amarillo", $con);
$result = mssql_query(" select ValeNo from dbo._SBOF_WebPage_ValesPorFactura ( CONVERT(VARCHAR,'$a')) order by ValeNo");
while($rows = mssql_fetch_array($result))
    {
        $documento = $rows['ValeNo'];
        $x = '.gif'; 
        $pdf->Cell( 160, 60, $pdf->Image(LAGGER.$documento.$x, $pdf->GetX(), $pdf->GetY(), 160,60), 1, 2, 'C', false );
        $pdf->ln(5);
    }
$pdf->Output('Boletas.pdf','I');

Solution

  • Solved! I use this:

    $pdf = new PDF('P','mm','Letter');
    $pdf->SetFont('Times','',10);
    $pdf->AliasNbPages();
    $pdf->SetMargins(15,15,10);
    $image_height = 150;
    $image_width = 58;
    $pdf->AddPage();
    $con = mssql_connect(DB_HOST3, DB_USER3, DB_PASS3, DB_NAME3);
    mssql_select_db("SBO_Amarillo", $con);
    $result = mssql_query(" select ValeNo,Nombre from dbo._SBOF_WebPage_ValesPorFactura ( CONVERT(VARCHAR,'$a')) order by ValeNo");
    while($rows = mssql_fetch_array($result))
        {
            $documento = $rows['ValeNo'];
            $name = $rows['Nombre'];            
            $x = '.gif'; 
            $rr = '   ';            
    
            $start_x = $pdf->GetX();
            $start_y = $pdf->GetY();
            $pdf->Cell(10,10,$name.$rr.$documento,0,1,'L');
            $pdf->Image(LAGGER.$documento.$x, $pdf->GetX(), $pdf->GetY() ,$image_height, $image_width) ;
            $pdf->SetXY( $start_x , $start_y + $image_width + 10);
                if ($start_y  >= 150) 
                    {
                        $pdf->AddPage();
                    }
        }
    $pdf->Output('Boletas.pdf','I');
    

    thank you!