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');

//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:

//we first create a document pdf:
$pdf =& new Cezpdf();
//setting up a counter
$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:
//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


//finally we print the whole document