Ver Mensaje Individual
  #1 (permalink)  
Antiguo 19/03/2007, 09:40
Avatar de ZydRick
ZydRick
 
Fecha de Ingreso: febrero-2005
Ubicación: Lima
Mensajes: 750
Antigüedad: 19 años, 2 meses
Puntos: 4
problema para crear pdf con libreria tcpdf

Hola gente, les cuento lo que me pasa, instalé en mi web la librería tcpdf para crear archivos pdf de los artículos que se publican en mi web, buscando por google encontré un manual que explica como usarlo y da una pequeña clase PHP para crear pdfs y un script de ejemplo, la clase es la siguiente

clasepdf.php
Código PHP:
<?php
    
class crearpdf {
        
        var 
$pdf;    
        var 
$nombre_archivo;
        var 
$descargar FALSE;
        var 
$patch K_PATH_MAIN// Patch Default del TCPDF
        
        // Funciones
        
        // Constructor
        
function crearpdf($nombre,$descargar) {    
             
// Instanciamos el Objeto
            
$this->pdf = new TCPDF(PDF_PAGE_ORIENTATIONPDF_UNITPDF_PAGE_FORMATtrue);
            
// Damos nombre al Archivo
            
$this->nombre_archivo=$nombre;
            
/*  $descargar TRUE Descargar Archivo
                True  Descargar Archivo
                False Crear Archivo
            */
            
if ($descargar) {
                
$this->descargar=TRUE;
            } else {
                
$this->descargar=FALSE;
            }
        }
        
        
// Cambiar Ruta del Archivo
        
function ruta($ruta) {    
            if (
is_dir($ruta)) {
                
$this->patch=$ruta;
                return 
TRUE;    
            } else {
                return 
FALSE;
            }
        }
        
        
// Crear el Archivo PDF
        
function texto($string) {
            
// $string debe ser un String
            
if ( is_string ($string) ) {
                
// Seteamos Info del Documento
                
$this->pdf->SetCreator(PDF_CREATOR);
                
$this->pdf->SetAuthor(PDF_AUTHOR);
                
$this->pdf->SetTitle($doc_title);
                
$this->pdf->SetSubject($doc_subject);
                
$this->pdf->SetKeywords($doc_keywords);
                
$this->pdf->SetHeaderData(PDF_HEADER_LOGOPDF_HEADER_LOGO_WIDTHPDF_HEADER_TITLEPDF_HEADER_STRING);
    
                
// Seteamos Margenes
                
$this->pdf->SetMargins(PDF_MARGIN_LEFTPDF_MARGIN_TOPPDF_MARGIN_RIGHT);
                
$this->pdf->SetAutoPageBreak(TRUEPDF_MARGIN_BOTTOM);
                
$this->pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
                
$this->pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
                
$this->pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); 
                
$this->pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN''PDF_FONT_SIZE_MAIN));
                
$this->pdf->setFooterFont(Array(PDF_FONT_NAME_DATA''PDF_FONT_SIZE_DATA));
                
$this->pdf->setLanguageArray($l);
                
// Inciciamos Documento 
                
$this->pdf->AliasNbPages();
                
$this->pdf->AddPage();
                
// Codigo de Barra para el Foot
                
$this->pdf->SetBarcode(date("Y-m-d H:i:s"time()));
                
// Escribimos el archivo
                
$string=utf8_encode($string);
                
$this->pdf->WriteHTML($stringtrue0);
                
// ¿ Creamos o Descargamos ?
                
if ($this->descargar) {
                    
$this->pdf->Output();
                } else {
                    
$this->pdf->Output($this->nombre_archivo,$this->$patch);
                }
            }
        }
    }
?>
y el script de ejemplo es el siguiente:

creapdf.php
Código PHP:
<?
    
// Include de la Libreria TCPDF
    
require_once('tcpdf/config/lang/eng.php');
    require_once(
'tcpdf/tcpdf.php');
    
// Incluimos la Clase class.crearpdf.php
    
include('clasepdf.php');
    
    
// Usamos La Clase class.crearpdf.php
    
$pdf = new crearpdf("archivo.pdf",1);
    
$pdf->texto('<font color="#0CAA0C"><h1><strong>Nuestro Segundo Ejemplo de PDF<br /></strong></h1></font>
    
    Ahora utilizamos la Simple Clase que hemos creado para realizar nuestro PDF de forma mas simple y podamos hacerlo desde cualquier parte de un Script.<br /><br />
    
    Recordemos que estamos Usando la Libreria/Clase <font color="#0033CC"><strong>TCPDF</strong></font> basada en <font color="#0CAA0C"><strong>FPDF</strong></font> con la <font color="#EF9E1F"><strong>Simple Clase</strong></font> , en nuestro Articulo en la <strong><i>Comunidad</i> <font color="#06AAEE">DeeRme</font></strong> Podemos Usar Distintos Tamaños de Letra, Colores y hasta Imagenes, eso si usando <font color="#DD01C6">XHTML</font> valido.
    <br><br>
    <img src="http://www.deerme.org/images/header2.jpg">'
);
?>
ahora bien, el problema que tengo es que cuando subo estos dos archivos a mi web y ejecuto me tira el siguiente mensaje:

Cita:
TCPDF error: Some data has already been output, can't send PDF file
mirando el script de la clase y el de ejemplo no pude ser capaz de ver donde está la falla por ello recurro a ustedes para que me echen una mano, espero que si alguien aquí ha usado dicha librería me pueda ayudar.

gracias por anticipado.

Saludos