Foros del Web » Programando para Internet » PHP »

Pdf - R&os

Estas en el tema de Pdf - R&os en el foro de PHP en Foros del Web. Wenas a todos, q tal? estoy usando la clase de R&OS para crear documentos pdf! normalmente los PDF q creaba eran totalmente estaticos, es decir, ...
  #1 (permalink)  
Antiguo 11/04/2007, 01:41
 
Fecha de Ingreso: enero-2005
Ubicación: Barcelona
Mensajes: 1.473
Antigüedad: 19 años, 3 meses
Puntos: 10
Pregunta Pdf - R&os

Wenas a todos,
q tal?

estoy usando la clase de R&OS para crear documentos pdf!
normalmente los PDF q creaba eran totalmente estaticos, es decir, cada campo en su sitio.
Ahora ya he empezado a crearlos dinamicos con resultados de consultas q me ocupan varias paginas, el problema q tengo es q no ser como hacer para q me llegue a cierta posicion me haga un salto de pagina, y a la vez no me corte la informacion q estoy mostrando...

alguna idea d como hacerlo?

gracias de antemano,

Saludos
__________________
"Cada hombre es el hijo de su propio trabajo"
Miguel de Cervantes Saavedra
"La experiencia es algo que no consigues hasta justo depués de necesitarla"
Laurence Olivier

Última edición por sergi_climent; 13/04/2007 a las 01:21
  #2 (permalink)  
Antiguo 13/04/2007, 01:32
 
Fecha de Ingreso: enero-2005
Ubicación: Barcelona
Mensajes: 1.473
Antigüedad: 19 años, 3 meses
Puntos: 10
Re: Pdf - R&os

Si sobre esta clase nadie lo sabe, con otra clase q no sea R&OS , es posible hacer lo q digo???
me aconsejais alguna?

saludos
__________________
"Cada hombre es el hijo de su propio trabajo"
Miguel de Cervantes Saavedra
"La experiencia es algo que no consigues hasta justo depués de necesitarla"
Laurence Olivier
  #3 (permalink)  
Antiguo 13/04/2007, 01:38
 
Fecha de Ingreso: agosto-2004
Mensajes: 118
Antigüedad: 19 años, 8 meses
Puntos: 1
Re: Pdf - R&os

Con la librería Fpdf he realizado documentos de 25 páginas, con absoluto control de las páginas y consultando bases de datos MySql.

http://www.fpdf.org/
  #4 (permalink)  
Antiguo 13/04/2007, 03:39
 
Fecha de Ingreso: enero-2005
Ubicación: Barcelona
Mensajes: 1.473
Antigüedad: 19 años, 3 meses
Puntos: 10
Re: Pdf - R&os

hola,

Tienes algun ejemplo de una pagina hehcha con fpdf en la cual se muestren los resultados de una consulta?

PD: Ya lo encontre en la misma Pagina! aunque si tienes mas ejemplos nunca esta de menos!

Código PHP:
<?php
//SHOW A DATABASE ON A PDF FILE
//FILE CREATED BY: Carlos José Vásquez Sáez
//YOU CAN CONTACT ME: [email protected]
//FROM PUNTA ARENAS, MAGALLANES

define('FPDF_FONTPATH','font/');
require(
'fpdf.php');

//Connect to your database
include("conectmysql.php");

//Select the Products you want to show in your PDF file
$result=mysql_query("select Code,Name,Price from Products ORDER BY Code",$link);
$number_of_products mysql_numrows($result);

//Initialize the 3 columns and the total
$column_code "";
$column_name "";
$column_price "";
$total 0;

//For each row, add the field to the corresponding column
while($row mysql_fetch_array($result))
{
    
$code $row["Code"];
    
$name substr($row["Name"],0,20);
    
$real_price $row["Price"];
    
$price_to_show number_format($row["Price"],',','.','.');

    
$column_code $column_code.$code."\n";
    
$column_name $column_name.$name."\n";
    
$column_price $column_price.$price_to_show."\n";

    
//Sum all the Prices (TOTAL)
    
$total $total+$real_price;
}
mysql_close();

//Convert the Total Price to a number with (.) for thousands, and (,) for decimals.
$total number_format($total,',','.','.');

//Create a new PDF file
$pdf=new FPDF();
$pdf->Open();
$pdf->AddPage();

//Fields Name position
$Y_Fields_Name_position 20;
//Table position, under Fields Name
$Y_Table_Position 26;

//First create each Field Name
//Gray color filling each Field Name box
$pdf->SetFillColor(232,232,232);
//Bold Font for Field Name
$pdf->SetFont('Arial','B',12);
$pdf->SetY($Y_Fields_Name_position);
$pdf->SetX(45);
$pdf->Cell(20,6,'CODE',1,0,'L',1);
$pdf->SetX(65);
$pdf->Cell(100,6,'NAME',1,0,'L',1);
$pdf->SetX(135);
$pdf->Cell(30,6,'PRICE',1,0,'R',1);
$pdf->Ln();

//Now show the 3 columns
$pdf->SetFont('Arial','',12);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(45);
$pdf->MultiCell(20,6,$column_code,1);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(65);
$pdf->MultiCell(100,6,$column_name,1);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(135);
$pdf->MultiCell(30,6,$columna_price,1,'R');
$pdf->SetX(135);
$pdf->MultiCell(30,6,'$ '.$total,1,'R');

//Create lines (boxes) for each ROW (Product)
//If you don't use the following code, you don't create the lines separating each row
$i 0;
$pdf->SetY($Y_Table_Position);
while (
$i $number_of_products)
{
    
$pdf->SetX(45);
    
$pdf->MultiCell(120,6,'',1);
    
$i $i +1;
}

$pdf->Output();
?>
saludos y gracias de antemano
__________________
"Cada hombre es el hijo de su propio trabajo"
Miguel de Cervantes Saavedra
"La experiencia es algo que no consigues hasta justo depués de necesitarla"
Laurence Olivier

Última edición por sergi_climent; 13/04/2007 a las 03:54
  #5 (permalink)  
Antiguo 13/04/2007, 04:12
 
Fecha de Ingreso: agosto-2004
Mensajes: 118
Antigüedad: 19 años, 8 meses
Puntos: 1
Re: Pdf - R&os

Bueno, haber que tal esto

Lo primero la estructura de la tabla de pruebas
Código PHP:
CREATE TABLE `tbl_pruebas` (
  `
Id_keyint(3NOT NULL auto_increment,
  `
Campo1varchar(6NOT NULL default '',
  `
Campo2varchar(6NOT NULL default '',
  `
Campo3varchar(6NOT NULL default '',
  `
Campo4varchar(6NOT NULL default '',
  `
Campo5varchar(6NOT NULL default '',
  `
Campo6varchar(6NOT NULL default '',
  `
Campo7varchar(6NOT NULL default '',
  
PRIMARY KEY  (`Id_key`)
TYPE=MyISAM PACK_KEYS=0 AUTO_INCREMENT=
Y ahora el código para quenerar el fichero
Código PHP:
<?
//===================================================================
    //Raquerir la clase 'pdf' para la generación de ficheros pdf
    
require('../clases/pdf/class.fpdf.php');
        

    
/////////////////////////////////////////////////////////////
    //       Conectar a base de datos local
    /////////////////////////////////////////////////////////////
    
DEFINE (DB_USER"MI USUARIO EN EL SERVIDOR DB");
    
DEFINE (DB_PASSWORD"MI CONTRASEÑA DB");
    
DEFINE (DB_HOST"127.0.0.1");         //conecta con servidor remoto
    
DEFINE (DB_NAME"NOMBRE DE LA BASE DE DATOS");


    
/////////////////////////////////////////////////////////////
    //       Conexión a mysql
    /////////////////////////////////////////////////////////////
    
$db_connection mysql_connect(DB_HOSTDB_USERDB_PASSWORD)
        or die(
Error_Mysql_Conect_DB());

    
//////////////////////////////////////////////////////////////
    //       Seleccionar db
    //////////////////////////////////////////////////////////////
    
mysql_select_db (DB_NAME);

//===================================================================

class PDF extends FPDF
{
    function 
PDF($orientation='l',$unit='mm',$format='A4')
    {    
    
//Llama al constructor de la clase padre
    
$this->FPDF($orientation,$unit,$format);
    
//Iniciacin de variables
    
$this->B=0;
    
$this->I=0;
    
$this->U=0;
    }

    function 
Header()
    {
    
//Logo
    
$this->Image('../imagenes/logo.png',5,8,33);
    
//Arial bold 15
    
$this->SetFont('Arial','B',15);
    
//Movernos a la derecha
    
$this->Cell(80);
    
//T tulo
    
$this->Cell(80,10,'Detalle de la tabla tbl_pruebas',1,0,'C');
    
//Salto de línea
    
$this->Ln(15);
    }

    
//Pie de página
    
function Footer()
    {
    
//Posicin: a 1,5 cm del final
    
$this->SetY(-15);
    
//Arial italic 8
    
$this->SetFont('Arial','I',8);
    
//Número de pgina
    
$this->Cell(0,10,'P gina '.$this->PageNo().'/{nb}',0,0,'C');
    }

    
//colorear la tabla    y cargar datos
    
function FancyTable($header,$data)
    {
    
//Colores, ancho de línea y fuente en negrita
    
$this->SetFillColor(255,0,0);
    
$this->SetTextColor(255);
    
$this->SetDrawColor(128,0,0);
    
$this->SetLineWidth(.3);
    
$this->SetFont('','B');
    
//Cabecera
    
$w=array(20,20,20,20,20,20,160);    
    for(
$i=0;$i<count($header);$i++)
        
$this->Cell($w[$i],7,$header[$i],1,0,'C',1);
    
$this->Ln();
    
//Restauración de colores y fuentes
    
$this->SetFillColor(224,235,255);
    
$this->SetTextColor(0);
    
$this->SetFont('');
    
//Datos
    
$fill=0;

    
$Sql "SELECT * FROM tbl_pruebas ORDER BY Campo1 ASC";
    
$Query mysql_query($Sql);
    
    
//Bucle para generar los datos
    
while($row mysql_fetch_array($Query))
        {
        
$this->Cell($w[0],6,$row['Campo1'],'LR',0,'C',$fill);
        
$this->Cell($w[1],6,$row['Campo2'],'LR',0,'C',$fill);
        
$this->Cell($w[2],6,$row['Campo3'],'LR',0,'C',$fill);
        
$this->Cell($w[3],6,$row['Campo4'],'LR',0,'C',$fill);
        
$this->Cell($w[4],6,$row['Campo5'],'LR',0,'C',$fill);
        
$this->Cell($w[5],6,$row['Campo6'],'LR',0,'C',$fill);
        
$this->Cell($w[6],6,$row['Campo7'],'LR',0,'L',$fill);        
        
$this->Ln();
        
$fill=!$fill;
        
        
//contador de línea para establecer líneas por página y cabecera
        
$cuenta +=;
        if(
$cuenta == 25)
            {
            
$this->Cell(array_sum($w),0,'','T');
            
$this->Ln();
            
$this->AddPage();
            
$this->SetFillColor(255,0,0);
            
$this->SetTextColor(255);
            
$this->SetDrawColor(128,0,0);
            
$this->SetLineWidth(.3);
            
$this->SetFont('','B');
            
//Cabecera
            
$w=array(20,20,20,20,20,20,160);    
            for(
$i=0;$i<count($header);$i++)
                 
$this->Cell($w[$i],7,$header[$i],1,0,'C',1);
                
$this->Ln();
                
$cuenta 0;
            
//Restauración de colores y fuentes
            
$this->SetFillColor(224,235,255);
            
$this->SetTextColor(0);
            
$this->SetFont('');
            }
        
        }    
    
$this->Cell(array_sum($w),0,'','T');
    }

}
//==============================================================

//Iniciar documento PDF
$pdf=new PDF();
$pdf->AliasNbPages();
//T tulos de las columnas
$header=array('Campo1','Campo2','Campo3','Campo4','Campo5','Campo6','Campo7');
$pdf->SetFont('Arial','',10);
$pdf->AddPage();
$pdf->FancyTable($header,$data);
$pdf->Output();

?>
Si deas que la página tenga menos líneas que las que te he establecido, busca lo siguiente
Código PHP:
        if($cuenta == 25)
            {
            
$this->Cell(array_sum($w),0,'','T');
            
$this->Ln();
            
$this->AddPage();
            
$this->SetFillColor(255,0,0);
            
$this->SetTextColor(255);
            
$this->SetDrawColor(128,0,0);
            
$this->SetLineWidth(.3);
            
$this->SetFont('','B');
            
//Cabecera
            
$w=array(20,20,20,20,20,20,160);    
            for(
$i=0;$i<count($header);$i++)
                 
$this->Cell($w[$i],7,$header[$i],1,0,'C',1);
                
$this->Ln();
                
$cuenta 0;
            
//Restauración de colores y fuentes
            
$this->SetFillColor(224,235,255);
            
$this->SetTextColor(0);
            
$this->SetFont('');
            } 
y cambian el valor "25" del condicional por el número de líneas que desees.
  #6 (permalink)  
Antiguo 13/04/2007, 04:50
 
Fecha de Ingreso: enero-2005
Ubicación: Barcelona
Mensajes: 1.473
Antigüedad: 19 años, 3 meses
Puntos: 10
Re: Pdf - R&os

he copiado el codigo tal cual pero he hecho algunos cambios para adaptarlo a mi BD y a mis campos. el codigo es el siguiente:
Código PHP:
<?php 
require("../../aut_verifica.inc.php"); 
error_reporting(E_ALL);
define('FPDF_FONTPATH','../funcions/font/');
include(
'../funcions/fpdf.php'); 
class 
PDF extends FPDF
{
    function 
PDF($orientation='l',$unit='mm',$format='A4')
    {    
    
//Llama al constructor de la clase padre
    
$this->FPDF($orientation,$unit,$format);
    
//Iniciacin de variables
    
$this->B=0;
    
$this->I=0;
    
$this->U=0;
    }

    function 
Header()
    {
    
//Logo
    //$this->Image('../imagenes/logo.png',5,8,33);
    //Arial bold 15
    
$this->SetFont('Arial','B',15);
    
//Movernos a la derecha
    
$this->Cell(80);
    
//T tulo
    
$this->Cell(80,10,'Detalle de la tabla tbl_pruebas',1,0,'C');
    
//Salto de línea
    
$this->Ln(15);
    }

    
//Pie de página
    
function Footer()
    {
    
//Posicin: a 1,5 cm del final
    
$this->SetY(-15);
    
//Arial italic 8
    
$this->SetFont('Arial','I',8);
    
//Número de pgina
    
$this->Cell(0,10,'Pagina '.$this->PageNo().'/{nb}',0,0,'C');
    }

    
//colorear la tabla    y cargar datos
    
function FancyTable($header,$data)
    {
    
//Colores, ancho de línea y fuente en negrita
    
$this->SetFillColor(255,0,0);
    
$this->SetTextColor(255);
    
$this->SetDrawColor(128,0,0);
    
$this->SetLineWidth(.3);
    
$this->SetFont('','B');
    
//Cabecera
    
$w=array(20,20,20,20,20,160);    
    for(
$i=0;$i<count($header);$i++)
        
$this->Cell($w[$i],7,$header[$i],1,0,'C',1);
    
$this->Ln();
    
//Restauración de colores y fuentes
    
$this->SetFillColor(224,235,255);
    
$this->SetTextColor(0);
    
$this->SetFont('');
    
//Datos
    
$fill=0;

    
/*******************************************************************************************/
    //var per montar la clausula where segons els parametres
    
$WHEREHAN='';
    
//var per pasar les dades per la url
    
$ur='';
    function 
FWhere($w) {
        return (
$w == '') ? ' WHERE ' "$w AND ";
    }
    
/*******************************************************************************************/
    //Recollim les variables del Formulari de busqueda
    
if (isset($_GET['id_localitat']) && ($_GET['id_localitat'] != 0)) {
        
$WHEREHAN Fwhere($WHEREHAN) . " id_localitat = $_GET[id_localitat]";
    }
    if (isset(
$_GET['id_seccio']) && ($_GET['id_seccio'] != 0)) {
        
$WHEREHAN Fwhere($WHEREHAN) . " id_seccio = $_GET[id_seccio]";
    }
    if (isset(
$_GET['ref_activitat']) && ($_GET['ref_activitat'] != '')) {
        
$WHEREHAN Fwhere($WHEREHAN) . " ref_averia LIKE '$_GET[ref_activitat]%'";
    }
    if (isset(
$_GET['id_maquina']) && ($_GET['id_maquina'] != 0)) {
        
$WHEREHAN Fwhere($WHEREHAN) . " id_maquina LIKE '$_GET[id_maquina]%'";
    }
    if (isset(
$_GET['data_desde']) && ($_GET['data_desde'] != '')) {
        
$data_desde=giradata($_GET[data_desde]);
        
$WHEREHAN Fwhere($WHEREHAN) . " data_avis >= '$data_desde'";
    }
    if (isset(
$_GET['data_fins']) && ($_GET['data_fins'] != '')){ 
        
$data_fins=giradata($_GET[data_fins]);
        
$WHEREHAN Fwhere($WHEREHAN) . " data_avis <= '$data_fins'";    
    }
    if (isset(
$_GET['prioritat']) && ($_GET['prioritat'] != 0)) {
        
$WHEREHAN Fwhere($WHEREHAN) . " prioritat = '$_POST[prioritat]'";
    }
    
    if (isset(
$_GET['tipus_maquina']) && ($_GET['tipus_maquina'] != 0)) {
        
$WHEREHAN Fwhere($WHEREHAN) . " tipus_maq = '$_GET[tipus_maquina]'";
    }    
    
$Sql "SELECT id_activitat, ref_activitat, id_maquina, id_localitat, 
            id_seccio, data_avis, descripcio
            FROM activitats $WHEREHAN ORDER BY data_avis DESC
            LIMIT 0,100"
;
    
$Query mysql_query($Sql);
    
    
//Bucle para generar los datos
    
while($row mysql_fetch_row($Query))
        {
        
//$this->Cell($w[0],6,$row['1'],'LR',0,'C',$fill);
        
$this->Cell($w[1],6,$row['1'],'LR',0,'C',$fill);
        
$this->Cell($w[2],6,$row['2'],'LR',0,'C',$fill);
        
$this->Cell($w[3],6,$row['3'],'LR',0,'C',$fill);
        
$this->Cell($w[4],6,$row['4'],'LR',0,'C',$fill);
        
$this->Cell($w[5],6,$row['5'],'LR',0,'C',$fill);
        
$this->Cell($w[6],6,$row['6'],'LR',0,'L',$fill);        
        
$this->Ln();
        
$fill=!$fill;
        
        
//contador de línea para establecer líneas por página y cabecera
        
$cuenta =0;
        if(
$cuenta == 25)
            {
            
$this->Cell(array_sum($w),0,'','T');
            
$this->Ln();
            
$this->AddPage();
            
$this->SetFillColor(255,0,0);
            
$this->SetTextColor(255);
            
$this->SetDrawColor(128,0,0);
            
$this->SetLineWidth(.3);
            
$this->SetFont('','B');
            
//Cabecera
            
$w=array(20,20,20,20,20,160);    
            for(
$i=0;$i<count($header);$i++)
                 
$this->Cell($w[$i],7,$header[$i],1,0,'C',1);
                
$this->Ln();
                
$cuenta 0;
            
//Restauración de colores y fuentes
            
$this->SetFillColor(224,235,255);
            
$this->SetTextColor(0);
            
$this->SetFont('');
            }
        
        }    
    
$this->Cell(array_sum($w),0,'','T');
    }

}
//==============================================================

//Iniciar documento PDF
$pdf=new PDF();
$pdf->AliasNbPages();
//Titulos de las columnas
$header=array('Ref.Averia','Maquina','Localidd','Seccion','Fecha','Descripcion');
$pdf->SetFont('Arial','',10);
$pdf->AddPage();
$pdf->FancyTable($header,$data);
$pdf->Output();
me lanza dos errores:
Notice: Undefined variable: data in C:\Archivos de programa\Apache Group\Apache2\htdocs\CONTROLMAQUINES\maquines\acti vitat\pdf_activitats.php on line 164

donde se declara Data? donde se le asignan los valore s data? no he sido capaz de verlo/encontrarlo...

Warning: Cannot modify header information - headers already sent by (output started at C:\Archivos de programa\Apache Group\Apache2\htdocs\CONTROLMAQUINES\maquines\acti vitat\pdf_activitats.php:164) in C:\Archivos de programa\Apache Group\Apache2\htdocs\CONTROLMAQUINES\maquines\func ions\fpdf.php on line 1022
FPDF error: Some data has already been output to browser, can't send PDF file

este ya estoy al caso... a ver si areglando el 1ero se arregla el segundo... q es lo mas posible!

Gracias de antemano!

saludos
__________________
"Cada hombre es el hijo de su propio trabajo"
Miguel de Cervantes Saavedra
"La experiencia es algo que no consigues hasta justo depués de necesitarla"
Laurence Olivier

Última edición por sergi_climent; 13/04/2007 a las 05:10
  #7 (permalink)  
Antiguo 16/04/2007, 00:50
 
Fecha de Ingreso: enero-2005
Ubicación: Barcelona
Mensajes: 1.473
Antigüedad: 19 años, 3 meses
Puntos: 10
Re: Pdf - R&os

Hola de nuevo...

alguna mano para este problema?

saludos y gracias de antemano!
__________________
"Cada hombre es el hijo de su propio trabajo"
Miguel de Cervantes Saavedra
"La experiencia es algo que no consigues hasta justo depués de necesitarla"
Laurence Olivier
  #8 (permalink)  
Antiguo 17/04/2007, 07:34
 
Fecha de Ingreso: enero-2005
Ubicación: Barcelona
Mensajes: 1.473
Antigüedad: 19 años, 3 meses
Puntos: 10
Re: Pdf - R&os

otra vez yo...

nadie?

__________________
"Cada hombre es el hijo de su propio trabajo"
Miguel de Cervantes Saavedra
"La experiencia es algo que no consigues hasta justo depués de necesitarla"
Laurence Olivier
  #9 (permalink)  
Antiguo 17/04/2007, 09:07
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 11 meses
Puntos: 2135
Re: Pdf - R&os

Data se define aqui:
Código PHP:
$pdf->FancyTable($header,$data); 
Leyendo la clase supongo, son tus datos desde una consulta SQL.

Salu2.
  #10 (permalink)  
Antiguo 17/04/2007, 09:17
 
Fecha de Ingreso: enero-2005
Ubicación: Barcelona
Mensajes: 1.473
Antigüedad: 19 años, 3 meses
Puntos: 10
Re: Pdf - R&os

Hola y gracias por responder!

pero en ningun momento veo q se le asigne nada a $data???

al copiar su ejemplo solo cambie los datos para poder ver como quedava este pdf, pero no hay manera...

-> alguien tiene un ejemplo de fpdf con una consulta de mysql ?

saludos y gracias de antemano
__________________
"Cada hombre es el hijo de su propio trabajo"
Miguel de Cervantes Saavedra
"La experiencia es algo que no consigues hasta justo depués de necesitarla"
Laurence Olivier
  #11 (permalink)  
Antiguo 17/04/2007, 09:21
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 11 meses
Puntos: 2135
Re: Pdf - R&os

Que problema tienes? ahi mismo te estoy diciendo solo tienes que asignarle data desde tu resultado de tu consulta y ya funciona.
Código PHP:
// Conectar a la base
mysql_connect();
mysql_select($db);

// Enviar el query
$query "SELECT * FROM tabla";
$result mysql_query$query );
$data = array();

// Obtener los resultados
while( $row mysql_fetch_row$result ) ) $data[] = $row;
mysql_free_result$result );
mysql_close();

//Iniciar documento PDF
$pdf=new PDF();
$pdf->AliasNbPages();
//Titulos de las columnas
$header=array('Ref.Averia','Maquina','Localidd','Seccion','Fecha','Descripcion');
$pdf->SetFont('Arial','',10);
$pdf->AddPage();
$pdf->FancyTable($header,$data);
$pdf->Output(); 
  #12 (permalink)  
Antiguo 17/04/2007, 09:49
 
Fecha de Ingreso: enero-2005
Ubicación: Barcelona
Mensajes: 1.473
Antigüedad: 19 años, 3 meses
Puntos: 10
Re: Pdf - R&os

ahora mismo tengo el siguiente codigo

Código PHP:
<?php 
require("../../aut_verifica.inc.php"); 
error_reporting(E_ALL);
define('FPDF_FONTPATH','../funcions/font/');
require(
'../funcions/fpdf.php'); 
    
/*******************************************************************************************/
    //var per montar la clausula where segons els parametres
    
$WHEREHAN='';
    function 
FWhere($w) {
        return (
$w == '') ? ' WHERE ' "$w AND ";
    }
    
/*******************************************************************************************/
    //Recollim les variables del Formulari de busqueda
    
if (isset($_GET['id_localitat']) && ($_GET['id_localitat'] != 0)) {
        
$WHEREHAN Fwhere($WHEREHAN) . " id_localitat = $_GET[id_localitat]";
    }
    if (isset(
$_GET['id_seccio']) && ($_GET['id_seccio'] != 0)) {
        
$WHEREHAN Fwhere($WHEREHAN) . " id_seccio = $_GET[id_seccio]";
    }
    if (isset(
$_GET['ref_activitat']) && ($_GET['ref_activitat'] != '')) {
        
$WHEREHAN Fwhere($WHEREHAN) . " ref_averia LIKE '$_GET[ref_activitat]%'";
    }
    if (isset(
$_GET['id_maquina']) && ($_GET['id_maquina'] != 0)) {
        
$WHEREHAN Fwhere($WHEREHAN) . " id_maquina LIKE '$_GET[id_maquina]%'";
    }
    if (isset(
$_GET['data_desde']) && ($_GET['data_desde'] != '')) {
        
$data_desde=giradata($_GET[data_desde]);
        
$WHEREHAN Fwhere($WHEREHAN) . " data_avis >= '$data_desde'";
    }
    if (isset(
$_GET['data_fins']) && ($_GET['data_fins'] != '')){ 
        
$data_fins=giradata($_GET[data_fins]);
        
$WHEREHAN Fwhere($WHEREHAN) . " data_avis <= '$data_fins'";    
    }
    if (isset(
$_GET['prioritat']) && ($_GET['prioritat'] != 0)) {
        
$WHEREHAN Fwhere($WHEREHAN) . " prioritat = '$_POST[prioritat]'";
    }
    
    if (isset(
$_GET['tipus_maquina']) && ($_GET['tipus_maquina'] != 0)) {
        
$WHEREHAN Fwhere($WHEREHAN) . " tipus_maq = '$_GET[tipus_maquina]'";
    }    
    
    
$sql "SELECT id_activitat, ref_activitat, id_maquina, id_localitat, 
            id_seccio, data_avis, descripcio
            FROM activitats $WHEREHAN ORDER BY data_avis DESC
            LIMIT 0,100"
;
    
$result mysql_query($sql);
    
// Obtener los resultados
while($row mysql_fetch_row($result)) $data[] = $row;
mysql_free_result$result );
mysql_close();

//Iniciar documento PDF
$pdf=new PDF();
$pdf->AliasNbPages();
//Titulos de las columnas
$header=array('Ref.Averia','Maquina','Localidd','Seccion','Fecha','Descripcion');
$pdf->SetFont('Arial','',10);
$pdf->AddPage();
$pdf->FancyTable($header,$data);
$pdf->Output();  
?>
y el error siguiente:

Fatal error: Class 'PDF' not found in C:\Archivos de programa\Apache Group\Apache2\htdocs\CONTROLMAQUINES\maquines\acti vitat\pdf_activitats.php on line 54
__________________
"Cada hombre es el hijo de su propio trabajo"
Miguel de Cervantes Saavedra
"La experiencia es algo que no consigues hasta justo depués de necesitarla"
Laurence Olivier
  #13 (permalink)  
Antiguo 17/04/2007, 10:35
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 11 meses
Puntos: 2135
Re: Pdf - R&os

Amigo, necesitas realmente ponerte a ver el codigo y lo que estas haciendo, necesitas incluir todo el codigo completo no solo partes, si no sabes de PHP, te recomiendo que primero leas un poco el manual, y algunos tutoriales antes de ponerte a picarle.
  #14 (permalink)  
Antiguo 18/04/2007, 00:37
 
Fecha de Ingreso: enero-2005
Ubicación: Barcelona
Mensajes: 1.473
Antigüedad: 19 años, 3 meses
Puntos: 10
Re: Pdf - R&os

Cita:
Iniciado por GatorV Ver Mensaje
Amigo, necesitas realmente ponerte a ver el codigo y lo que estas haciendo, necesitas incluir todo el codigo completo no solo partes, si no sabes de PHP te recomiendo que primero leas un poco el manual, y algunos tutoriales antes de ponerte a picarle.[/.
solo queria una codigo de copy&paste para ver q tal generaba una consulta de bastantes resultados... la verdad q solo me conecte a la pagina de fpdf para descargarme la clase pero bueno.. ya me mirare esta clase cuando tenga tiempo.

Yo he usado la de R&OS como he puesto en el titulo... pero me he encontrado con alguna limitacion y queria probar con otra a ver q tal iba.

se agradece igualmente!


PD. llevo 2 años aficionandome al PHP, pero por falta de tiempo no he podido ponerme al 100% con los manuales, y tal pero ya tengo hecho mis pinitos... etc etc etc

con un poco de lectura y tiempo se conseigue.
x si alguien le sirve...

Código PHP:
<?php 
require("../../aut_verifica.inc.php"); 
error_reporting(E_ALL); 
define('FPDF_FONTPATH','../funcions/font/'); 
include(
'../funcions/fpdf.php'); 
/*******************************************************************************************/
    //var per montar la clausula where segons els parametres
    
$WHEREHAN='';
    function 
FWhere($w) {
        return (
$w == '') ? ' WHERE ' "$w AND ";
    }
    
/*******************************************************************************************/
    //Recollim les variables del Formulari de busqueda
    
if (isset($_GET['id_localitat']) && ($_GET['id_localitat'] != 0)) {
        
$WHEREHAN Fwhere($WHEREHAN) . " id_localitat = $_GET[id_localitat]";
    }
    if (isset(
$_GET['id_seccio']) && ($_GET['id_seccio'] != 0)) {
        
$WHEREHAN Fwhere($WHEREHAN) . " id_seccio = $_GET[id_seccio]";
    }
    if (isset(
$_GET['ref_activitat']) && ($_GET['ref_activitat'] != '')) {
        
$WHEREHAN Fwhere($WHEREHAN) . " ref_averia LIKE '$_GET[ref_activitat]%'";
    }
    if (isset(
$_GET['id_maquina']) && ($_GET['id_maquina'] != 0)) {
        
$WHEREHAN Fwhere($WHEREHAN) . " id_maquina LIKE '$_GET[id_maquina]%'";
    }
    if (isset(
$_GET['data_desde']) && ($_GET['data_desde'] != '')) {
        
$data_desde=giradata($_GET[data_desde]);
        
$WHEREHAN Fwhere($WHEREHAN) . " data_avis >= '$data_desde'";
    }
    if (isset(
$_GET['data_fins']) && ($_GET['data_fins'] != '')){ 
        
$data_fins=giradata($_GET[data_fins]);
        
$WHEREHAN Fwhere($WHEREHAN) . " data_avis <= '$data_fins'";    
    }
    if (isset(
$_GET['prioritat']) && ($_GET['prioritat'] != 0)) {
        
$WHEREHAN Fwhere($WHEREHAN) . " prioritat = '$_POST[prioritat]'";
    }
    
    if (isset(
$_GET['tipus_maquina']) && ($_GET['tipus_maquina'] != 0)) {
        
$WHEREHAN Fwhere($WHEREHAN) . " tipus_maq = '$_GET[tipus_maquina]'";
    }    
    
    
$sql "SELECT id_activitat, ref_activitat, id_maquina, id_localitat, 
            id_seccio, data_avis, descripcio
            FROM activitats $WHEREHAN ORDER BY data_avis DESC
            LIMIT 0,1000"
;
    
$result mysql_query($sql);
    
$data=array();
    
    
//Bucle para generar los datos 
    
while($row mysql_fetch_row($result)) 
        { 
        
$data[] = $row;
        } 
class 
PDF extends FPDF 

    function 
PDF($orientation='l',$unit='mm',$format='A4'
    {     
    
//Llama al constructor de la clase padre 
    
$this->FPDF($orientation,$unit,$format); 
    
//Iniciacin de variables 
    
$this->B=0
    
$this->I=0
    
$this->U=0
    } 

    function 
Header() 
    { 
    
//Logo 
    //$this->Image('../imagenes/logo.png',5,8,33); 
    //Arial bold 15 
    
$this->SetFont('Arial','B',15); 
    
//Movernos a la derecha 
    
$this->Cell(80); 
    
//T tulo 
    
$this->Cell(80,10,'Detalle de la tabla tbl_pruebas',1,0,'C'); 
    
//Salto de línea 
    
$this->Ln(15); 
    } 

    
//Pie de página 
    
function Footer() 
    { 
    
//Posicin: a 1,5 cm del final 
    
$this->SetY(-15); 
    
//Arial italic 8 
    
$this->SetFont('Arial','I',8); 
    
//Número de pgina 
    
$this->Cell(0,10,'Pagina '.$this->PageNo().'/{nb}',0,0,'C'); 
    } 

    
//colorear la tabla    y cargar datos 
    
function FancyTable($header,$data
    { 
    
//Colores, ancho de línea y fuente en negrita 
    
$this->SetFillColor(255,0,0); 
    
$this->SetTextColor(255); 
    
$this->SetDrawColor(128,0,0); 
    
$this->SetLineWidth(.3); 
    
$this->SetFont('','B'); 
    
//Cabecera 
    
$w=array(20,20,20,20,20,160);     
    for(
$i=0;$i<count($header);$i++) 
        
$this->Cell($w[$i],7,$header[$i],1,0,'C',1); 
    
$this->Ln(); 
    
//Restauración de colores y fuentes 
    
$this->SetFillColor(224,235,255); 
    
$this->SetTextColor(0); 
    
$this->SetFont(''); 
    
//Datos 
    
$fill=0
    
    
/*******************************************************************************************/
    //var per montar la clausula where segons els parametres
    
$WHEREHAN='';
    
/*******************************************************************************************/
    //Recollim les variables del Formulari de busqueda
    
if (isset($_GET['id_localitat']) && ($_GET['id_localitat'] != 0)) {
        
$WHEREHAN Fwhere($WHEREHAN) . " id_localitat = $_GET[id_localitat]";
    }
    if (isset(
$_GET['id_seccio']) && ($_GET['id_seccio'] != 0)) {
        
$WHEREHAN Fwhere($WHEREHAN) . " id_seccio = $_GET[id_seccio]";
    }
    if (isset(
$_GET['ref_activitat']) && ($_GET['ref_activitat'] != '')) {
        
$WHEREHAN Fwhere($WHEREHAN) . " ref_averia LIKE '$_GET[ref_activitat]%'";
    }
    if (isset(
$_GET['id_maquina']) && ($_GET['id_maquina'] != 0)) {
        
$WHEREHAN Fwhere($WHEREHAN) . " id_maquina LIKE '$_GET[id_maquina]%'";
    }
    if (isset(
$_GET['data_desde']) && ($_GET['data_desde'] != '')) {
        
$data_desde=giradata($_GET[data_desde]);
        
$WHEREHAN Fwhere($WHEREHAN) . " data_avis >= '$data_desde'";
    }
    if (isset(
$_GET['data_fins']) && ($_GET['data_fins'] != '')){ 
        
$data_fins=giradata($_GET[data_fins]);
        
$WHEREHAN Fwhere($WHEREHAN) . " data_avis <= '$data_fins'";    
    }
    if (isset(
$_GET['prioritat']) && ($_GET['prioritat'] != 0)) {
        
$WHEREHAN Fwhere($WHEREHAN) . " prioritat = '$_POST[prioritat]'";
    }
    
    if (isset(
$_GET['tipus_maquina']) && ($_GET['tipus_maquina'] != 0)) {
        
$WHEREHAN Fwhere($WHEREHAN) . " tipus_maq = '$_GET[tipus_maquina]'";
    }    
    
    
$sql "SELECT id_activitat, ref_activitat, id_maquina, id_localitat, 
            id_seccio, data_avis, descripcio
            FROM activitats $WHEREHAN ORDER BY data_avis DESC
            LIMIT 0,1000"
;
    
$result mysql_query($sql);
    
$data=array();
    
    
//Bucle para generar los datos 
    
while($row mysql_fetch_row($result)) 
        { 
        
//$data[] = $row;
        //$this->Cell($w[0],6,$row['1'],'LR',0,'C',$fill); 
        
$this->Cell($w[0],6,$row['1'],'LR',0,'C',$fill); 
        
$this->Cell($w[1],6,$row['2'],'LR',0,'C',$fill); 
        
$this->Cell($w[2],6,$row['3'],'LR',0,'C',$fill); 
        
$this->Cell($w[3],6,$row['4'],'LR',0,'C',$fill); 
        
$this->Cell($w[4],6,$row['5'],'LR',0,'C',$fill); 
        
$this->Cell($w[5],6,$row['6'],'LR',0,'L',$fill);         
        
$this->Ln();         
        
$fill=!$fill
         
        
//contador de línea para establecer líneas por página y cabecera 
        
$cuenta =0
        if(
$cuenta == 25
            { 
            
$this->Cell(array_sum($w),0,'','T'); 
            
$this->Ln(); 
            
$this->AddPage(); 
            
$this->SetFillColor(255,0,0); 
            
$this->SetTextColor(255); 
            
$this->SetDrawColor(128,0,0); 
            
$this->SetLineWidth(.3); 
            
$this->SetFont('','B'); 
            
//Cabecera 
            
$w=array(20,20,20,20,20,160);     
            for(
$i=0;$i<count($header);$i++) 
                 
$this->Cell($w[$i],7,$header[$i],1,0,'C',1); 
                
$this->Ln(); 
                
$cuenta 0
            
//Restauración de colores y fuentes 
            
$this->SetFillColor(224,235,255); 
            
$this->SetTextColor(0); 
            
$this->SetFont(''); 
            } 
         
        }     
    
$this->Cell(array_sum($w),0,'','T'); 
    } 


//============================================================== 

//Iniciar documento PDF 
$pdf=new PDF(); 
$pdf->AliasNbPages(); 
//Titulos de las columnas 
$header=array('Ref.Averia','Maquina','Localidd','Seccion','Fecha','Descripcion'); 
$pdf->SetFont('Arial','',10); 
$pdf->AddPage(); 
$pdf->FancyTable($header,$data); 
$pdf->Output();
?>
saludos y gracias por vuestra paciencia para uno sin tiempo
__________________
"Cada hombre es el hijo de su propio trabajo"
Miguel de Cervantes Saavedra
"La experiencia es algo que no consigues hasta justo depués de necesitarla"
Laurence Olivier

Última edición por sergi_climent; 18/04/2007 a las 01:08
  #15 (permalink)  
Antiguo 18/04/2007, 09:13
 
Fecha de Ingreso: enero-2004
Ubicación: Medellin
Mensajes: 178
Antigüedad: 20 años, 3 meses
Puntos: 8
Re: Pdf - R&os

muchas gracias por el codigo, aunuqe veo que eres un poco desorganizado.

el bloque propio del fptf lo puedes dejar arriba y las consultas SQL debajo de este, asi se ve con mayor claridad como funciona!!
  #16 (permalink)  
Antiguo 18/04/2007, 09:23
 
Fecha de Ingreso: enero-2005
Ubicación: Barcelona
Mensajes: 1.473
Antigüedad: 19 años, 3 meses
Puntos: 10
Re: Pdf - R&os

hola..
Cita:
Iniciado por vicman Ver Mensaje
muchas gracias por el codigo, aunuqe veo que eres un poco desorganizado.
el bloque propio del fptf lo puedes dejar arriba y las consultas SQL debajo de este, asi se ve con mayor claridad como funciona!!
disculpar por el desorden pero por falta de tiempo no he tenido tiempo de dejarlo bonito...
lo he probado esta mañana, he visto q funcionava y q el rendimiento era bueno con mas de 100 resultados y asi se ha quedado!

cuando disponga de unos minutos ya mirare de arreglar-lo y dejarlo bien para q se entienda.
o vos. mismo... postea aqui el codigo organizadito y asi acabamos antes!

saludos
__________________
"Cada hombre es el hijo de su propio trabajo"
Miguel de Cervantes Saavedra
"La experiencia es algo que no consigues hasta justo depués de necesitarla"
Laurence Olivier
  #17 (permalink)  
Antiguo 09/05/2007, 09:52
 
Fecha de Ingreso: noviembre-2003
Mensajes: 499
Antigüedad: 20 años, 5 meses
Puntos: 7
Re: Pdf - R&os

hola:

Estoy trabajando con tu script y cuando lo corro me pide una carpeta imagenes/logo.png, la creo y me salta el mismo error como si no lo hubiese creado, que será??

Gracias de antemano
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Tema Cerrado




La zona horaria es GMT -6. Ahora son las 12:40.