PHP - Some data has already been output to browser, can't send PDF file

 
Vista:
sin imagen de perfil

Some data has already been output to browser, can't send PDF file

Publicado por gaaa18 (5 intervenciones) el 06/06/2014 21:19:49
este es mi error amigos a ver si me podrian ayudar ya que no me imprime el reporte e pdf:

Conexion exitosa TCPDF ERROR: Some data has already been output to browser, can't send PDF file

y este es mi codigo:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
 
	include('fpdf.php');
 
	require_once('../tcpdf/config/lang/eng.php');
	require_once('../tcpdf/tcpdf.php');
	require("../modelo/consulta.php");
 
	$objConsulta= new consulta();
	$perfil="";
	$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
 
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('http://alvarenga.comule.com');
$pdf->SetTitle('Reporte de Usuarios');
$pdf->SetSubject('Tutirial de reportes en PDF con PHP y MySQL');
$pdf->SetKeywords('Reporte, usuario, php, mysql');
 
 
 
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
 
//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, 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);
 
//set some language-dependent strings
$pdf->setLanguageArray($l);
 
// ---------------------------------------------------------
 
// set default font subsetting mode
$pdf->setFontSubsetting(true);
 
$pdf->SetFont('helvetica', '', 9, '', true);
 
// Add a page 
// This method has several options, check the source code documentation for more information.
$pdf->setPrintHeader(false); //no imprime la cabecera ni la linea 
$pdf->setPrintFooter(true); // imprime el pie ni la linea 
$pdf->AddPage();
 
//*************
  ob_end_clean();//rompimiento de pagina
  //ob_clean();
//************* 
 
$html = $objConsulta->reportePdfUsuarios();
$pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);
 
$pdf->Output('Reporte usuarios.pdf', 'I');
?>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de xve
Val: 3.943
Oro
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

Some data has already been output to browser, cant send PDF file

Publicado por xve (6935 intervenciones) el 07/06/2014 09:48:46
Hola, este error que te esta dando, creo que es porque en algun momento de tu código, o en alguno de los includes, muestras algo por pantalla, ya sea un echo, un error, o alguna cosa, que no deja al finalizar el archivo imprimir únicamente el documento pdf.

Puedes revisar que no haya ninguna echo o error?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

Some data has already been output to browser, cant send PDF file

Publicado por galvarenga (5 intervenciones) el 07/06/2014 19:19:29
gracias por tu comentario pero he estado revisando y no encuentro el error y los únicos echo que tengo es cuando me conecta a la base de datos al ingresar los registros que eso me lo hace bien el problema es que no me los muestra en un reporte pdf.
saludos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de xve
Val: 3.943
Oro
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

Some data has already been output to browser, cant send PDF file

Publicado por xve (6935 intervenciones) el 08/06/2014 17:19:58
Hola, a que echo's te refieres con los de la base de datos... En el código que muestras no hay ninguno.

El error te indica eso, por lo que de seguro en algún sitio esta... prueba a quitar las cabeceras... tendrías que visualizar el código html que te da el problema.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Some data has already been output to browser, cant send PDF file

Publicado por galvarenga (1 intervención) el 09/06/2014 03:34:41
buenas ya revise y comente el echo y igual nada estas son mis clases:

esta es conexión

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
class Conexion{
    var $ruta;
    var $usuario;
    var $contrasena;
    var $baseDatos;
 
    function Conexion(){
        $this->ruta="localhost"; //
        $this->usuario="german"; //usuario que tengas definido
        $this->contrasena="alvarenga"; //contraseña que tengas definidad
        $this->baseDatos="personas"; //base de datos personas, si quieres utilizar otra base de datos solamente cambiala
    }
 
    function conectarse(){
        //---------------------------TIPO DE CONEXION 1-----------------------------------
        /*$conectarse= mysql_connect($this->ruta,$this->usuario, $this->contrasena) or die(mysql_error()); //conexion al BD             
        if($conectarse){
            mysql_select_db($this->baseDatos);
            return($conectarse);
        }else{  
            return ("Error");
            }*/
        //------------------------TIPO DE CONEXION 2 - RECOMENDADA--------------------------------------------- 
        $enlace = mysqli_connect($this->ruta, $this->usuario, $this->contrasena, $this->baseDatos);
        if($enlace){
            echo "Conexion exitosa";    //si la conexion fue exitosa nos muestra este mensaje como prueba, despues lo puedes poner comentarios de nuevo: //
        }else{
            die('Error de Conexión (' . mysqli_connect_errno() . ') '.mysqli_connect_error());
        }
        return($enlace);
        mysqli_close($enlace); //cierra la conexion a nuestra base de datos, un ounto de seguridad importante.
    }
}
?>


esta es de controlador.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
	require("../modelo/consulta.php");
	$objConsulta = new consulta();
 
	if(isset($_POST["registrar"])){
		$registro = $objConsulta->registrarUsuario($_POST["nombres"],$_POST["apellidos"],$_POST["telefono"],$_POST["ciudad"]);
		if($registro){
		?>
			<script>
				alert('Registro Exitoso');
				location.href="../vista/index.php";
            </script>
		<?php
		}else{
		?>
			<script>
				alert('Registro Exitoso');
				location.href="../vista/index.php";
            </script>
		<?php
		}
	}
?>


esta es de consulta.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
 
	require "../conexion/conexion.php";
	class consulta{
		var $conn;
		var $conexion;
		function consulta(){
			$this->conexion= new  Conexion();
			$this->conn=$this->conexion->conectarse();
		}
		//-----------------------------------------------------------------------------------------------------------------------
		function registrarUsuario($nombres, $apellidos, $telefono, $ciudad){
			$exito="";
			$sql_insert="insert into usuarios (nombres, apellidos, telefono, ciudad) values ('".$nombres."','".$apellidos."','".$telefono."','".$ciudad."')";
			$rs=mysqli_query($this->conn,$sql_insert) or die(mysql_error());
			if($rs){
				$exito="Registro exitoso";
			}
			return $exito;
		}
		//-----------------------------------------------------------------------------------------------------------------------
		function reportePdfUsuarios(){
			$html="";
			$sql="select * from usuarios order by codigo";
			$rs=mysqli_query($this->conn,$sql);
			$i=0;
 
			$html=$html.'<div align="center">
			Reporte de usuarios registrados en la Base de Datos.
			<br /><br />			
			<table border="0" bordercolor="#0000CC" bordercolordark="#FF0000">';
			$html=$html.'<tr bgcolor="#FF0000"><td><font color="#FFFFFF">C&oacute;digo</font></td><td><font color="#FFFFFF">Nombres</font></td><td><font color="#FFFFFF">Apellidos</font></td><td><font color="#FFFFFF">Tel&eacute;fono</font></td><td><font color="#FFFFFF">Ciudad</font></td></tr>';
			while ($row = mysqli_fetch_array($rs)){
				if($i%2==0){
					$html=  $html.'<tr bgcolor="#95B1CE">';
				}else{
					$html=$html.'<tr>';
				}
				$html = $html.'<td>';
				$html = $html. $row["codigo"];
				$html = $html.'</td><td>';
				$html = $html. $row["nombres"];
				$html = $html.'</td><td>';
				$html = $html. $row["apellidos"];
				$html = $html.'</td><td>';
				$html = $html. $row["telefono"];
				$html = $html.'</td><td>';
				$html = $html. $row["ciudad"];
				$html = $html.'</td></tr>';
				$i++;
			}
			$html=$html.'</table></div>';
     		 return ($html);
		}
		//-----------------------------------------------------------------------------------------------------------------------		
	}
?>


y mi index.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Reportes</title>
</head>
 
<body>
	<form method="post" action="../control/controlador.php">
	<div align="center">
    <font color="#FF0000" size="+3" face="Lucida Sans Unicode, Lucida Grande, sans-serif">
	    <b><i>Generar reportes </i></b>
    </font>
    <br />
    <font size="+2" color="#006600" face="Palatino Linotype, Book Antiqua, Palatino, serif">Autor: German Alvarenga</font>
    <br /><br />
    <table border="0">
    <tr>
    	<td>Nombres</td>
        <td><input type="text" name="nombres" required="required" autofocus="autofocus" maxlength="50" /></td>
    </tr><tr>
    	<td>Apellidos</td>
        <td><input type="text" name="apellidos" required="required" maxlength="50" /></td>
    </tr><tr>
    	<td>Tel&eacute;fono</td>
        <td><input type="text" name="telefono" required="required" maxlength="10" /></td>
    </tr>
    <tr>
    	<td>Ciudad</td>
        <td><input type="text" name="ciudad" required="required" maxlength="30" /></td></td>
    </tr>
    <tr>
	    <td><input type="submit" name="registrar" value="Registrar Usuario" /></td>
    	<td><a href="reporte_usuarios_pdf.php" target="_blank">Generar Reporte</a></td>
    </tr>
    </table>
 
    <br />
 
        </div>
        </form>
</body>
</html>
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de xve
Val: 3.943
Oro
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

Some data has already been output to browser, cant send PDF file

Publicado por xve (6935 intervenciones) el 09/06/2014 08:05:00
Nada mas ver tu código, veo esto:
1
echo "Conexion exitosa";
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

Some data has already been output to browser, cant send PDF file

Publicado por gavarenga (5 intervenciones) el 10/06/2014 05:20:45
igual quite ese echo y me sigue dando el error


TCPDF ERROR: Some data has already been output to browser, can't send PDF file
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar