php - How to improve rendering in FPDF? -
<?php $factuurnr = $_get['factuurnr']; require('fpdf/fpdf.php'); //connect database include("db_connect.php"); //create new pdf file $pdf=new fpdf(); //open file $pdf->open(); //disable automatic page break $pdf->setautopagebreak(false); //add first page $pdf->addpage(); //set initial y axis position per page $y_axis_initial = 25; //print column titles actual page $pdf->setfillcolor(232, 232, 232); $pdf->setfont('arial', 'b', 12); $pdf->sety($y_axis_initial); $pdf->setx(25); $pdf->cell(30, 6, 'klantnummer', 1, 0, 'l', 1); $pdf->cell(100, 6, 'factuurnummer', 1, 0, 'l', 1); $pdf->cell(30, 6, 'bedrag', 1, 0, 'r', 1); $y_axis = $y_axis + $row_height; //select products want show in pdf file $query="select * facturen factuurnummer = '$factuurnr'"; $result=mysql_query($query); //initialize counter $i = 0; //set maximum rows per page $max = 25; //set row height $row_height = 6; while($row = mysql_fetch_array($result)) { //if current row last one, create new page , print column title if ($i == $max) { $pdf->addpage(); //print column titles current page $pdf->sety($y_axis_initial); $pdf->setx(25); $pdf->cell(30, 6, 'klantnummer', 1, 0, 'l', 1); $pdf->cell(100, 6, 'factuurnummer', 1, 0, 'l', 1); $pdf->cell(30, 6, 'bedrag', 1, 0, 'r', 1); //go next row $y_axis = $y_axis + $row_height; //set $i variable 0 (first row) $i = 0; } $klantnummer = $row['klantnummer']; $factuurnummer = $row['factuurnummer']; $bedrag = $row['bedrag']; $pdf->sety($y_axis); $pdf->setx(25); $pdf->cell(30, 6, $klantnummer, 1, 0, 'l', 1); $pdf->cell(100, 6, $factuurnummer, 1, 0, 'l', 1); $pdf->cell(30, 6, $bedrag, 1, 0, 'r', 1); //go next row $y_axis = $y_axis + $row_height; $i = $i + 1; } mysql_close; //create file $pdf->output(); ?>
i'm trying use fpdf generate pdf info mysql. honest, working, rendering off, , i'm new fpdf figure out.
the data mysql gets rendered above table headers, , i'm not sure why.
probably initial set of $y_axis wrong. try this:
$y_axis = $y_axis_initial + $row_height;
i think should replace 2 of 3 '$y_axis = ...' lines (the last 1 ok).
Comments
Post a Comment