martes, 10 de agosto de 2010

EZpdf: How to print several pages given different variables in one PDF document

I am using the ezpdf class in order to print several reports in PDF format using PHP programming.

I finally found a way to print different pages. 

This is the situation:

for each page, my php script retrieves a specific variable value from a database to print a report. Then the page is generated and i add another page using $pdf->ezNewPage() function and so on until my loop finishes.

Finally i call the function $php->ezStream to print all the pages in just one PDF file.

here it's my code:

//script para imprimir todos los bloques en un sólo archivo pdf !!! Sehr Geil! oder?
include ('class.ezpdf.php');
include('conn.inc');
mysql_select_db('evaluacioneducativa',$link);

//empezaremos aquí el loop, para cada bloque hay que imprimir el reporte:
//buscando los distintos bloques de la generacion 2008
$fetch_bloques=mysql_query("SELECT DISTINCT (CONCAT(.. AS bloque_seccion
FROM bloque ...
WHERE ...") or die('Hubo un error al buscar los bloques porque:
'.mysql_error());

//we first create a document pdf:
$pdf =& new Cezpdf();
//setting up a counter
$contados=mysql_num_rows($fetch_bloques);
$counter_pages=1; //initializing this counter so that we won't print the last page as a blank one.
//for each variable found in the database:
while($row_bloque=mysql_fetch_array($fetch_bloques))
{//INICIO DEL SUPER WHILE
$bloque=$row_bloque['bloque_seccion'];
//echo "bloque: $bloque
";
//vamos a imprimir el documento en cuestión:
include "basic_format_pdf_08.php";
//we open a new page using an IF clause to avoid printing the last page which will be a blank one
if($counter_pages<$contados)
{
$pdf->ezNewPage();
}
$counter_pages++;

}//FIN DEL SUPER WHILE

//finally we print the whole document
$pdf->ezStream();
?>
 

 

Tags