Programación Web y Scripting > PHP

 agradeceria una mano, para modificar la creacion de un pdf

<< < (2/2)

pacorubio77:
otro de los ficheros y a los que mireis el código os hará falta será formatoPDF.php

--- Código: PHP --- // create new PDF document$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);  // set document information$pdf->SetCreator(PDF_CREATOR);$pdf->SetAuthor('Delicatino GmbH');$pdf->SetTitle('Catalog');$pdf->SetSubject('Mate-tee.de');$pdf->SetKeywords('Yerba mate'); // set default header data$pdf->SetHeaderData('logo-mate-tee-delicatino.jpg', 40, 'Delicatino GmbH', "Neidenburger Str. 8n28207 BremennDeutschlandnTel: 0049 421 43 77 361nFax:  0049 421 43 77 362"); // set header and footer fonts$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); // set default monospaced font$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); //set margins$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP+15, PDF_MARGIN_RIGHT);$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);$pdf->SetFooterMargin(PDF_MARGIN_FOOTER); //set auto page breaks$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); //set image scale factor$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO*2);  //set some language-dependent strings$pdf->setLanguageArray($l);  // --------------------------------------------------------- // set font$pdf->SetFont('times', '', 8); // add a page$pdf->AddPage(); // --------------------------------------------------------- $r=''; $letzte_categories='';$products=f_cargarProductos($opcion,$select_languages,$valor_categories,$valor_products);//$r.=f_cabecera_productos();$r.=f_cabecera_tabla_productos(); //si elimino esta linea sólo me saldría por pantalla modelo$i=0;while($row=mysql_fetch_array($products)){    $r.=f_fila_producto();  //muestra las filas por producto    if(($i%12)==11) {        $r.=f_pie_tabla_productos();  //modifica cuadricula        $letzte_categories='';        $r=flt($r);        $r=utf8_encode($r);        $pdf->writeHTML($r, true, false, false, true, '');        $pdf->AddPage();        $r='';        $r.=f_cabecera_tabla_productos();    }    $i++;}@mysql_free_result($products); $r.=f_pie_tabla_productos(); $r=flt($r);$r=utf8_encode($r); $pdf->writeHTML($r, true, false, false, true, ''); // --------------------------------------------------------- //Close and output PDF document$pdf->Output('catalog.pdf', 'I');//echo $r;//echo '<pre>';//print_r($pdf); //============================================================+// END OF FILE                                                 //============================================================+ ?>    
y el fichero cabecera.php, en el que se definen lo que se utilizará


--- Código: PHP --- <?php // guardar coomo iso $g_url_base_images="http://www.mate-tee.de/catalog/images/"; $cabecera=array ("tipos" =>array  ( // Tipos de variables    "categories_name" => "S", // String=Cadena    "mostrar"=>"C",    // Chackbox=Casilla Sí/No    "mod"=>"A", // A=enlace    "foto"=>"F", // Foto    "modelo"=>"S",    "nombre"=>"T",  // Texto    "unidad"=>"I", // Integer    "precio1"=>"E", // Euro    "precio2"=>"E",    "precio3"=>"E",    "precio_final"=>"E",    "precio_especial"=>"E"   ),"3" =>array  ( // Español    "categories_name" => "Categoría",    "mostrar"=>"Mostrar",    "mod"=>"Modificar",    "foto"=>"Foto",    "modelo"=>"Modelo",    "nombre"=>"Descripción",    "unidad"=>"Unidadesrnpor paquete",    "precio1"=>"Precio", // Precio minorista    "precio2"=>"Precio mayorista", //"PreciornHaendler Drn+ ohne UiD Nr",            //cg=4 SELECT products_id AS pid, customers_group_price AS precio FROM products_groups WHERE customers_group_id=4    "precio3"=>"Precio mayorista", //"PreciornHaendler EU Arnmit Ident. Nummer",    //gc=3 SELECT products_id AS pid, customers_group_price AS precio FROM products_groups WHERE customers_group_id=3    "precio_final"=>"Preciornfinal",    "precio_especial"=>"Precio en oferta" // Precio especial   ),"2" =>array  ( //Deutsch    "categories_name" => "Produktkategorie",    "mostrar"=>"Zeigen",    "mod"=>"Modifizieren",    "foto"=>"Bild",    "modelo"=>"Art. Nr.",    "nombre"=>"Beschreibung",       "unidad"=>"Verpackungseinheit",    "precio1"=>"Preis", // Precio minorista / Preis Uvp    "precio2"=>"Preis Händler", // "PreisrnHaendler Drn+ ohne UiD Nr",    "precio3"=>"Preis Händler", //"PreisrnHaendler EU Arnmit Ident.Nummer",    "precio_final"=>"Preis final",    "precio_especial"=>"Angebotspreis" // Precio especial / Preis especial   ),"1" =>array  ( //English    "categories_name" => "Category",    "mostrar"=>"Show",    "mod"=>"Modify",    "foto"=>"Image",    "modelo"=>"Number",    "nombre"=>"Name",    "unidad"=>"Packaging unit",    "precio1"=>"Price",    "precio2"=>"Wholesale price", //"PricernHaendler Drn+ ohne UiD Nr",    "precio3"=>"Wholesale price", //"PricernHaendler EU Arnmit Ident.Nummer",    "precio_final"=>"Precio final",    "precio_especial"=>"Special price" // Precio especial   ));//echo $cabecera["3"]["precio3"] //Saca en pantalla: "Precio a partir de 500 Euros"?>   
ESPERO ME AYUDEN, DESPUES DE LEER TANTO CÓDIGO

F_Tanori:

--- Cita de: "pacorubio77" ---...

Como veis aqui se hace una llamada a onClick="javascript:generarPDF();">
eso se encuentra en un fichero javascript que es el siguiente

function generarHTML() { generarGenerico('HTML'); }
function generarCSV() { generarGenerico('CSV'); }
function generarPDF() { generarGenerico('PDF'); }


--- Código: PHP --- function generarGenerico(tipo) {    var f = window.document.opciones;    var comp_products = false;    if(f && f.valor_products && f.box_products){        f.valor_products.value = "0";        var max = f.box_products.length;        for (var idx = 0; idx < max; idx++) {            if (eval("f.box_products[" + idx + "].checked") == true) {                f.valor_products.value=f.valor_products.value+","+eval("f.box_products[" + idx + "].value");                comp_products = true;           }        }    }    if (comp_products==true) {        f.action = "formato"+tipo+".php";        f.submit();    }else{        alert("Debe marcar algún producto para generar "+tipo);    }}    
y ahi tengo una pregunta

var f = window.document.opciones;
en esta sentencia f que guarda? cuanto vale f?


--- Fin de la cita ---

f hace referencia a un formulario, el formulario que contiene los botones de generar debe llamarse opciones

las funciones f_cargarProductos y f_fila_producto son las que necesitas revisar para agregarle el caso correspondiente, para devolver las columnas que son necesarias en la consulta, y las que quieras mostrar en el pdf

Saludos

pacorubio77:
comentarte un asunto, yo creo que el fichero que deberia tocar es el siguiente, dime si acierto o no
En este fichero imprime segun la opcion que cojas? te lo pregunto



--- Código: PHP --- if($opcion==1) {    //Mostramos los registros    $data = array();    $header = array();    while ($row=mysql_fetch_array($products)){        foreach ($row as $key => $value) { $row[$key]=flt($value); }        if ($row["categories_name"]!=$letzte_categories) {            //Column titles            $header = array(                    $cabecera[$select_languages]['categories_name'],                    $cabecera[$select_languages]["modelo"],                    $cabecera[$select_languages]["nombre"],                    $cabecera[$select_languages]["unidad"],                    $cabecera[$select_languages]["precio1"],                    $cabecera[$select_languages]["precio2"],                    $cabecera[$select_languages]["precio3"],                );            $types = array(                    $cabecera['tipos']['categories_name'],                    $cabecera['tipos']["modelo"],                    $cabecera['tipos']["nombre"],                    $cabecera['tipos']["unidad"],                    $cabecera['tipos']["precio1"],                    $cabecera['tipos']["precio2"],                    $cabecera['tipos']["precio3"],                );            for($i = 0; $i < count($header); $i++)                $header[$i]=utf8_encode($header[$i]);        }        //Data loading        $data[] = array(                $row["categories_name"],                $row["products_model"],                $row["products_name"],                $row["products_ve"],                numeros::zeigenPrice($row['products_price'],$row['tax_rate']),                numeros::formatear($row["precio2"],2,""),                numeros::formatear($row["precio3"],2,"")            );        $letzte_categories=$row["categories_name"];    }    if(count($data)>0){ $pdf->ColoredTable($header,$types,$data,$opcion); } // print colored table}elseif($opcion==2){    //Mostramos los registros    while ($row=mysql_fetch_array($products))   {        foreach ($row as $key => $value) { $row[$key]=flt($value); }        if ($row["categories_name"]!=$letzte_categories) {              //Column titles            $header = array(                    $cabecera[$select_languages]['categories_name'],                    $cabecera[$select_languages]["foto"],                    $cabecera[$select_languages]["modelo"],                    $cabecera[$select_languages]["nombre"],                    $cabecera[$select_languages]["unidad"],                    $cabecera[$select_languages]["precio1"],                    $cabecera[$select_languages]["precio2"],                    $cabecera[$select_languages]["precio3"]                );            $types = array(                    $cabecera['tipos']['categories_name'],                    $cabecera['tipos']["foto"],                    $cabecera['tipos']["modelo"],                    $cabecera['tipos']["nombre"],                    $cabecera['tipos']["unidad"],                    $cabecera['tipos']["precio1"],                    $cabecera['tipos']["precio2"],                    $cabecera['tipos']["precio3"]                );        }        //Data loading        $data[] = array(                $row["categories_name"],                $g_url_base_images.$row["products_image"],                $row["products_model"],                $row["products_name"],                $row["products_ve"],                numeros::zeigenPrice($row['products_price'], $row['tax_rate']),                numeros::formatear($row["precio2"],2,""),                numeros::formatear($row["precio3"],2,"")            );        $letzte_categories=$row["categories_name"];    }    if(count($data)>0){ $pdf->ColoredTable($header,$types,$data,$opcion); } // print colored table}elseif($opcion==3){    //Mostramos los registros    while ($row=mysql_fetch_array($products))   {        foreach ($row as $key => $value) { $row[$key]=flt($value); }        if ($row["categories_name"]!=$letzte_categories) {              //Column titles            $header = array(                    $cabecera[$select_languages]['categories_name'],                    $cabecera[$select_languages]["modelo"],                    $cabecera[$select_languages]["nombre"],                    $cabecera[$select_languages]["unidad"],                    $cabecera[$select_languages]["precio1"],                    $cabecera[$select_languages]["precio_especial"]                );            $types = array(                    $cabecera['tipos']['categories_name'],                    $cabecera['tipos']["modelo"],                    $cabecera['tipos']["nombre"],                    $cabecera['tipos']["unidad"],                    $cabecera['tipos']["precio1"],                    $cabecera['tipos']["precio_especial"]                );        }        //Data loading        $data[] = array(                $row["categories_name"],                $row["products_model"],                $row["products_name"],                $row["products_ve"],                ($row['specials_price']==NULL)?numeros::zeigenPrice($row['products_price'], $row['tax_rate']):numeros::zeigenPrice($row['products_price'], $row['tax_rate']),                numeros::zeigenPrice($row['specials_price'], $row['tax_rate'])            );        $letzte_categories=$row["categories_name"];    }    if(count($data)>0){ $pdf->ColoredTable($header,$types,$data,$opcion); } // print colored table}elseif($opcion==4){    //Mostramos los registros    while ($row=mysql_fetch_array($products))   {        foreach ($row as $key => $value) { $row[$key]=flt($value); }        if ($row["categories_name"]!=$letzte_categories) {              //Column titles            $header = array(                    $cabecera[$select_languages]['categories_name'],                    $cabecera[$select_languages]["foto"],                    $cabecera[$select_languages]["modelo"],                    $cabecera[$select_languages]["nombre"],                    $cabecera[$select_languages]["unidad"],                    $cabecera[$select_languages]["precio1"],                    $cabecera[$select_languages]["precio_especial"]                );            $types = array(                    $cabecera['tipos']['categories_name'],                    $cabecera['tipos']["foto"],                    $cabecera['tipos']["modelo"],                    $cabecera['tipos']["nombre"],                    $cabecera['tipos']["unidad"],                    $cabecera['tipos']["precio1"],                    $cabecera['tipos']["precio_especial"]                );        }        //Data loading        $data[] = array(                $row["categories_name"],                $row["products_image"],                $row["products_model"],                $row["products_name"],                $row["products_ve"],                ($row['specials_price']==NULL)?numeros::zeigenPrice($row['products_price'], $row['tax_rate']):numeros::zeigenPrice($row['products_price'], $row['tax_rate']),                numeros::zeigenPrice($row['specials_price'], $row['tax_rate'])            );        $letzte_categories=$row["categories_name"];    }    if(count($data)>0){ $pdf->ColoredTable($header,$types,$data,$opcion); } // print colored table}  @mysql_free_result($products); //Close and output PDF document$pdf->Output('catalog.pdf', 'I'); //============================================================+// END OF FILE                                                 //============================================================+    
Si hay algo que no entiendes, comúnicamelo.

Un saludo.

Navegación

[0] Índice de Mensajes

[*] Página Anterior

Ir a la versión completa