0
I have a report that I’m using the FPDF class. While I was developing it on my local machine everything was wonderful, now that I did hosting the files on the kinghost, I started having problems with it.
The error shown by the page is:
FPDF error: Some data has already been output, can’t send PDF file (output Started at /home/brancosistemas/www/teste/inicio.php:12)
I’ve already reviewed everything, followed several tips and suggestions I found around (I’ve been trying to solve the problem since yesterday), and none of them worked. It accuses that the output was started on my homepage...
I wonder if anyone can help me with this?
PDF code:
<?php
include "fpdf/fpdf.php";
session_start();
// Turn off all error reporting
error_reporting(0);
//selecionando exame da empresa.
$sql = "SELECT RQ_EXAME FROM db043
WHERE RQ_IMPR = 'P'
AND RQ_EMPR = ".$_SESSION['cliente']['C_CODI']." ";
$res = mysql_query($sql);
$row = mysql_fetch_assoc($res);
$registro = $row['RQ_EXAME'];
//selecionado cabeçalho do exame
$sql = "SELECT R.RQ_EXAME, R.RQ_VALOR, R.RQ_DATA, R.RQ_DEPE, E.C_FANT EMPR,
L.C_FANT LABO, concat_ws(', ', L.C_ENDE, L.C_NUME) C_ENDE, L.C_TIPO, F.F_NOME, F.F_FONE
FROM db043 R
JOIN db02 E ON (R.RQ_EMPR=E.C_CODI)
JOIN db02 L ON (R.RQ_LABO=L.C_CODI)
JOIN db021 F ON (R.RQ_EMPR=F.F_EMPR) AND (R.RQ_FUNC=F.F_CODI)
WHERE R.RQ_EXAME = $registro";
$res = mysql_query($sql);
$cabec = mysql_fetch_assoc($res);
$emissao = date_create($cabec["RQ_DATA"]);
$emissao = date_format($emissao, 'd/m/Y');
$sql = "SELECT R.RQ_TIPO, E.NOME
FROM db0431 R
JOIN db26 E ON (R.RQ_TIPO=E.CODIGO)
WHERE R.RQ_EXAME = $registro";
$res = mysql_query($sql);
$nome_exame = '';
while($exames = mysql_fetch_assoc($res)){
if ($nome_exame == ''){
$nome_exame = $exames["NOME"];
} else {
$nome_exame = $nome_exame.", ".$exames["NOME"];
}
}
$nome_exame = utf8_decode(" > > > > > [ ".$nome_exame." ] < < < < < ");
$pdf = new FPDF();
$pdf->AddPage('P','A4');
/******************** DADOS DA PRIMEIRA VIA ********************/
for ($i=0;$i < 2;$i++) {
//com essa $pos eu defino a posição de impressão das duas vias no laço.
$pos = 0;
if($i == 1){
$pos = 152;
}
$pdf->Line(10, 10+$pos, 10, 135+$pos);//linha esquerda
$pdf->Line(200, 10+$pos, 200, 135+$pos);//linha direita
$pdf->Line(10, 10+$pos, 200, 10+$pos); //linha superior
/*** dados do primeiro bloco ****/
$pdf->Image('http://www.biovel.com.br/img/convenios/convenio-sindconvenio.jpg', 12, 12+$pos, 0, 18, 'JPG');
$pdf->SetFont('Arial','B',20);
$pdf->Text(53,19+$pos, 'SINDCONVENIOS');
$pdf->SetFont('Arial','B',12);
$pdf->Text(49,25+$pos, utf8_decode('Medicina e Segurança do Trabalho'));
$pdf->SetFont('Arial', 'B', 10);
$pdf->Text(145,20+$pos, 'Fone(45) 3223-4662');
$pdf->SetFont('Arial','',10);
$pdf->Text(130,15+$pos, utf8_decode('CEP: 85.812-001 - CASCAVEL - PARANÁ'));
$pdf->Text(124,25+$pos, utf8_decode('Av. Brasil, 5964 - 1º Andar - Salas - 12, 13 e 14'));
$pdf->Line(10, 30+$pos, 200, 30+$pos);//linha que encerra o primeiro bloco
/*** dados do segundo bloco ****/
$pdf->SetFont('Arial','B',12);
$pdf->Text(15,35+$pos, utf8_decode('REQUISIÇÃO'));
$pdf->Text(120,35+$pos, $emissao);
$pdf->SetFont('Arial','',10);
$pdf->Text(44,34.5+$pos, utf8_decode('- Exame - Saúde Ocupacional'));
$pdf->Text(110,34.5+$pos, utf8_decode('Data:'));
$pdf->SetFont('Arial','',8);
$pdf->Text(189,34.5+$pos, str_pad($registro, 6, "0", STR_PAD_LEFT));
$pdf->Line(10, 37+$pos, 200, 37+$pos);//linha que encerra o segundo bloco
/*** dados do terceiro bloco ****/
$pdf->SetFont('Arial','',9);
$pdf->Text(19.6,42+$pos, utf8_decode('Empresa:'));
$pdf->Text(21.3,48+$pos, utf8_decode('Usuário:'));
$pdf->Text(15,54+$pos, utf8_decode('Dependente:'));
$pdf->SetFont('Arial','B',9);
$pdf->Text(35,42+$pos, utf8_decode($cabec["EMPR"]));
$pdf->Text(35,48+$pos, utf8_decode($cabec["F_NOME"]));
$pdf->Text(35,54+$pos, utf8_decode($cabec["RQ_DEPE"]));
$pdf->Text(170,42+$pos, utf8_decode($cabec["F_FONE"]));
$pdf->Line(10, 57+$pos, 200, 57+$pos);//linha que encerra o terceiro bloco
/*** dados do quarto bloco ****/
$pdf->SetFont('Arial','',9);
$pdf->Text(65,61.2+$pos, '( ) Consulta');
$pdf->Text(110,61.2+$pos, '( ) Exame');
$pdf->SetFont('Arial','B',9);
$pdf->Text(170,61.2+$pos, 'OCUPACIONAL');
if($cabec["C_TIPO"] == 'C') {
$pdf->Text(66.3,61.2+$pos, 'X');
} else {
$pdf->Text(111.3,61.2+$pos, 'X');
}
$pdf->Line(10, 64+$pos, 200, 64+$pos);//linha que encerra o quarto bloco
/*** dados do quinto bloco ****/
$pdf->SetFont('Arial','',9);
$pdf->Text(12,68+$pos, utf8_decode('Clínica/Laboratório:'));
$pdf->Text(27,77+$pos, utf8_decode('Exames:'));
$pdf->SetFont('Arial','B',9);
$pdf->Text(40,68+$pos, utf8_decode($cabec["LABO"]));
$pdf->Text(40,72+$pos, utf8_decode($cabec["C_ENDE"]));
$pdf->SetXY(40,75);
$pdf->MultiCell(150,4,$nome_exame, 0, 'J', false);
$pdf->Line(10, 101+$pos, 200, 101+$pos);//linha que encerra o quinto bloco
/*** dados do sexto bloco ****/
$pdf->SetFont('Arial','',9);
$pdf->Text(20,115+$pos, '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -');
$pdf->Text(35,118+$pos, utf8_decode('Carimbo e Assinatura da Empresa'));
$pdf->Text(113,115+$pos, '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -');
$pdf->Text(135,118+$pos, utf8_decode('Assinatura do Usuário'));
$pdf->Line(10, 121+$pos, 200, 121+$pos);//linha que encerra o sexto bloco
/*** dados do sétimo bloco ****/
$pdf->SetFont('Arial','B',9);
$pdf->Text(55,125.5+$pos, utf8_decode('Os valores dos exames só terão validade quando fornecidos pela SINDCONVÊNIOS'));
$pdf->SetFont('Arial','',9);
$total = $cabec["RQ_VALOR"] * 100;
$total = str_pad($total, 6, "0", STR_PAD_LEFT);
$pdf->Text(13,125.5+$pos, "A0".$total."B");
$pdf->Line(10, 128+$pos, 200, 128+$pos);//linha que encerra o sexto bloco
/*** dados do sétimo bloco ****/
$pdf->SetFont('Arial','I',9);
$pdf->Text(15,133+$pos, utf8_decode('obs: A Guia não pode ser rasurada e nem utilizada para outra finalidade, podendo comprometer o pagamento da mesma.'));
$pdf->Line(10, 135+$pos, 200, 135+$pos);//linha inferior
}
$pdf->Text(10,150, '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -');
if($registro > 0){
ob_end_clean();
if(!ob_get_contents()){
$pdf->Output("Requisição_".$registro.".PDF", 'D');
} else {
echo ob_get_contents();
}
}
// segundo o manual do php... fechar essa tag é desnecessário nesse caso, mas já tentei de ambas as formas... "? >"
<?
session_start();
include "admin/inc/conexao.php";
$raiz = "http://".$_SERVER['HTTP_HOST']."/teste";
?>
<!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>
<base href="<?=$raiz?>"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link href="../css/estilo.css" rel="stylesheet" type="text/css"/>
<script src="../js/jquery-2.1.1.min.js"></script>
<script src="../js/funcoes.js"></script>
<title>SINDConvênios</title>
</head>
<body>
<div class="geral">
<div class="topo">
<a href="principal" title="Clique aqui para retornar a Pagina inicial!"><div class="logo">SINDConvênios</div></a>
<?
if(isset($_SESSION['cliente'])){
?>
</br>
<fieldset class="user_ident">
<legend>Usuario</legend>
<label><?=$_SESSION['cliente']['C_NOME']?></label></br>
<a class="linkusr" href="javascript:logoff()">Sair!</a>
</fieldset>
<?
}
?>
<br clear="all"/>
</div>
<br clear="all"/>
</div>
<div class="conteudo">
<?
if(isset($_SESSION['cliente'])){
$permitidos = array('co_requisicao', 'empresas', 'funcionarios', 'imprimir', 'login', 'nv_requisicao', 'principal');
if((isset($_GET['p'])) and (array_search($_GET['p'], $permitidos) !== false))
include "inc/".$_GET['p'].".php";
else
include "inc/principal.php";
} else {
include "inc/login.php";
}
?>
</div>
</body>
</html>
You looked at that question
– rray
What is line 12 in
inicio.php
?– Jorge B.
Jorge, line 12 has this: <base href="<?= $root? >"/> "<?".
– Paulo Rodrigo
I just added the "start.php" code next to the topic.
– Paulo Rodrigo
You checked the archive database?
– rray
I checked... all the files are in UTF-8 without GOOD.
– Paulo Rodrigo
Checked if kinghost supports short tags in php?
– RodrigoBorth
Yes Rodrigo, they support short tags.
– Paulo Rodrigo
Place these two lines at the beginning of the file that is in trouble and see if any more Warning appears.
ini_set('display_errors', true);
 error_reporting(E_ALL);
What is the php version of both hosts?– rray
@lost 5.3 in both. When I added these lines to print.php it continued with the same message... Now when I include them in the beginning.php the message was: Notice: A Session had already been Started - ignoring session_start() in /home/brancosistemas/www/teste/inc/imprimir.php on line 4. ...
– Paulo Rodrigo