Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

danluc

Php-Pdf

Recommended Posts

BOA NOITE, TO TENTANDO CRIAR UM PDF BASEADO NO MEU CODIGO, TO SEGUINDO ALGUNS TUTORIAIS , MAIS NÃO TO CONSEGUINDO, TA DANDO ERRO..

CODIGO:

<h1><strong style="font-size: 36px">Consulta Claro</strong></h1> 
    <hr/>

<h2>Pesquisar Contato:</h2>
<form action="Clientes.php" method="post"> Infome o numero: 
<input type="text" name="txtnome" id="txtnome">
<input type=submit value="Consultar"><br>
  <hr>
<h2>Resultados da pesquisa:</h2></form>

<?php 
require_once('conexao.php');
import_request_variables("gP");
// Verifica se existe a variável txtnome 
if (isset($_POST["txtnome"])) { $nome = $_POST["txtnome"];



//Query simples para busca dos dados
$sql = "SELECT usuarios.Usuario , bancoclaro.TELEFONE, bancoclaro.NUMERO, bancoclaro.HORA, bancoclaro.UF, bancoclaro.VALOR, bancoclaro.ID FROM bancoclaro 
INNER JOIN usuarios ON usuarios.telefone = bancoclaro.TELEFONE
WHERE 
 F5 = '$nome'
AND  (Numero NOT IN (SELECT telcm.telefoneCM FROM telcm)OR Numero IS NULL) AND ATIVO <> 2
";

$busca = mysql_query($sql);
//Verificação das linhas encontradas.
if(mysql_num_rows($busca) > 0)
{
?>
<table width="870" border="1" cellpadding="1" cellspacing="0" id="listacliente">
              <tr>
                <td height="44" colspan="6">
                <table width="865" border="1" cellpadding="8" cellspacing="0">
                  <tr align="center" valign="middle">
                    <td width="152">Nome</td>
                    <td width="175">N°.Discado</td>
                    <td width="116">Hora</td>
                    <td width="213">Uf</td>
                    <td width="51">Valor</td>
                    <td width="55">Inf.</td>
                  </tr>
                </table>
                </td>
              </tr>
   <?php while ($ver = mysql_fetch_array($busca))
{
 ?>
    
                
                <tr align="center" valign="middle" onMouseOver="style.backgroundColor='#FF6'" onMouseOut="style.backgroundColor='#FFF'">
                  <td width="166"><?php echo $ver["Usuario"]; ?></td>
                  <td width="195"><?php echo $ver['NUMERO']; ?></td>
                  <td width="126"><?php echo $ver['HORA']; ?></td>
                  <td width="227"><?php echo $ver['UF']; ?></td>
                  <td width="67"><?php echo $ver['VALOR']; ?></td>
                  <td width="74">
                 <?php echo '<form action="deletar.php" method="post">
						<input type="checkbox" value='.$ver["ID"].' name="btnDele" id="btnDele">
						<input type=submit value="DELETE"></form><br>'; ?></td>
                  </td>
                </tr>
                

                <?php }?>
                
            </table> 
<?php
}else{
	//Caso não tenha registros a consulta, exibimos a mensagem.
	print 'Sem Registros';	

}}
?>



<?php
require_once('conexao.php');
import_request_variables("gP");
// Verifica se existe a variável txtnome 
if (isset($_POST["txtnome"])) { $nome = $_POST["txtnome"];{



$sql = "SELECT usuarios.Usuario ,bancoclaro.TELEFONE, bancoclaro.NUMERO, bancoclaro.HORA, bancoclaro.DURACAO, 
bancoclaro.VALOR, REPLACE(SUM(REPLACE(bancoclaro.VALOR, ',', '.')),'.',',') AS VALOR_TOTAL
FROM bancoclaro INNER JOIN usuarios ON usuarios.telefone = bancoclaro.TELEFONE
WHERE 
 F5 = '$nome'
AND  (Numero NOT IN (SELECT telcm.telefoneCM FROM telcm)OR Numero IS NULL) AND Valor > 0 AND ATIVO <> 2
";

$busca = mysql_query($sql);
//Verificação das linhas encontradas.
if(mysql_num_rows($busca) > 0)
{
?>
<table width="867" border="1" cellpadding="0" cellspacing="0" id="listacliente">
              <tr>
                <td height="44" colspan="6">
                <table width="865" border="1" cellpadding="8" cellspacing="0">
                  <tr align="center" valign="middle">
                    <th width="353">NOME</th>
					<th width="474">VALOR_TOTAL</th>
                  </tr>
                </table>
                </td>
</tr>
   <?php while ($ver = mysql_fetch_array($busca))
{
 ?>
       
<table width="865" border="1" cellpadding="0" cellspacing="0" id="listacliente">
  <tr align="center" valign="middle">
    <td width="368" height="24" style="font-size: 16px"><?php echo $ver["Usuario"]; ?></td>
    <td width="493" style="font-size: 16px"><?php echo $ver['VALOR_TOTAL']; ?></td>
  </tr>
</table>
               
                

                <?php }?>


<a href="relatorio.php?rel=bancoclaro&ID="<?php echo $ver['ID']; ?>" title="Gerar PDF" 
target="_self">Gerar PDF</a>

<?php
}else{
	//Caso não tenha registros a consulta, exibimos a mensagem.
	print 'Sem Registros';	

} 
}
}
?>

RELATORIO PARA GERAR O PDF:

<?php
$html='
<html>
<style type="text/css">
hr {
	border: 2px solid #39F;
}
.textos {
	font-family: Verdana, Geneva, sans-serif;
	font-size: 13px;
	line-height: 18px;
	color: #333;
}
td {
	font-family: Verdana, Geneva, sans-serif;
	font-size: 12px;
	line-height: 18px;
	color: #E31515;
}
body {
	font-family: Calibri;
}
#dados {
	font-family: Calibri;
	font-size: 16px;
}
h2 {
	font-family: Calibri;
	color: #09F;
}
</style>
<body>
';

$html.='<table width="657" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="384">Consulta Claro </td>
    <td width="52" align="right"><img src="exemplo.jpg" width="230" height="70"></td>
  </tr>
</table>
<hr />
<h2>Ficha Cadastral</h2>
<div id="dados">
<table width="870" border="1" cellpadding="1" cellspacing="0" id="listacliente">
              <tr>
                <td height="44" colspan="6">
                <table width="865" border="1" cellpadding="8" cellspacing="0">
                  <tr align="center" valign="middle">
                    <td width="152">Nome</td>
                    <td width="175">N°.Discado</td>
                    <td width="116">Hora</td>
                    <td width="213">Uf</td>
                    <td width="51">Valor</td>
                    <td width="55">Inf.</td>
                  </tr>
                </table>
                </td>
              </tr>
     <td width="166">'.$ver['Usuario'].'</td>
                  <td width="195">'.$ver['NUMERO'].'</td>
                  <td width="126">'.$ver['HORA'].'/td>
                  <td width="227">'.$ver['UF'].'</td>
                  <td width="67">'.$ver['VALOR'].'</td>
</div>
<hr />
<p class="textos">Empresa Clair Mont - Todos os Direitos Reservados.</p>
</body>
</html>';
?>
<?php
mysql_free_result($busca);

//Aqui nós chamamos a class do dompdf
require_once('dompdf/dompdf_config.inc.php');

//É fundamental definir o TIMEZONE de nossa região para que não tenhamos problemas com a geração.
date_default_timezone_set('America/Sao_Paulo');

//Aqui eu estou decodificando o tipo de charset do documento, para evitar erros nos acentos das letras e etc.
$html = utf8_decode($html);

//Instanciamos a class do dompdf para o processo
$dompdf= new DOMPDF();

//Aqui nós damos um LOAD (carregamos) todos os nossos dados e formatações para geração do PDF
$dompdf->load_html($html);

$dompdf->set_paper('legal','landscape');

//Aqui nós damos início ao processo de exportação (renderizar)
$dompdf->render();

//por final forçamos o download do documento, coloquei a nomeclatura com a data e mais um string no final.
$dompdf->stream(date('d/m/Y').'_cliente.pdf');
?>

O ERRO:

 

( ! ) Catchable fatal error: Argument 1 passed to DOMNode::appendChild() must be an instance of DOMNode, null given, called in C:\Program Files (x86)\VertrigoServ\www\BancoClaro\bkp\dompdf\include\table_frame_decorator.cls.php on line 320 and defined in C:\Program Files (x86)\VertrigoServ\www\BancoClaro\bkp\dompdf\include\frame.cls.php on line 440 Call Stack # Time Memory Function Location 1 0.0107 342984 {main}( ) ..\relatorio.php:0 2 1.0302 736520 DOMPDF->render( ) ..\relatorio.php:102 3 1.2414 4829520 Frame_Decorator->reflow( ) ..\dompdf.cls.php:417 4 1.2414 4829520 Page_Frame_Reflower->reflow( ) ..\frame_decorator.cls.php:387 5 1.2417 4830808 Frame_Decorator->reflow( ) ..\page_frame_reflower.cls.php:78 6 1.2417 4830808 Block_Frame_Reflower->reflow( ) ..\frame_decorator.cls.php:387 7 1.3018 6587600 Frame_Decorator->reflow( ) ..\block_frame_reflower.cls.php:408 8 1.3018 6587600 Block_Frame_Reflower->reflow( ) ..\frame_decorator.cls.php:387 9 1.3040 6597048 Frame_Decorator->reflow( ) ..\block_frame_reflower.cls.php:408 10 1.3040 6597048 Table_Frame_Reflower->reflow( ) ..\frame_decorator.cls.php:387 11 1.3045 6600400 Table_Frame_Reflower->get_min_max_width( ) ..\table_frame_reflower.cls.php:395 12 1.3045 6600400 Table_Frame_Decorator->normalise( ) ..\table_frame_reflower.cls.php:494 13 1.3057 6607112 Frame->append_child( ) ..\table_frame_decorator.cls.php:320

 

Compartilhar este post


Link para o post
Compartilhar em outros sites

Para testar, substitua

 

 

//Aqui nós damos um LOAD (carregamos) todos os nossos dados e formatações para geração do PDF
$dompdf->load_html($html);
 
$dompdf->set_paper('legal','landscape');
 
//Aqui nós damos início ao processo de exportação (renderizar)
$dompdf->render();
 
//por final forçamos o download do documento, coloquei a nomeclatura com a data e mais um string no final.
$dompdf->stream(date('d/m/Y').'_cliente.pdf');

 

por

 

 

echo $html;

 

Depois cole o html gerado no site da W3C para ver se você não se esqueceu de fechar nenhuma outra tag ou outros erros.

 

http://validator.w3.org/#validate_by_input

 

Parece que você se esqueceu de fechar a tag "Table".

Compartilhar este post


Link para o post
Compartilhar em outros sites

Surgem algumas perguntas:

  • Qual é a página que exibe o pdf? o código está completo?
  • Onde você declara o valor da variavel $ver na página que gera o pdf? parece que você não declara.
  • No HTML as informações aparecem? acredito que também não

Observei também esta linha:

 

<a href="relatorio.php?rel=bancoclaro&ID="<?php echo $ver['ID']; ?>" title="Gerar PDF" target="_self">Gerar PDF</a>

 

Observe as aspas repetidas

 

bancoclaro&ID="<?php echo $ver['ID']; ?>" 

 

Observei também que todos estes erros parecem estar relacionados a distração, sugiro que você programe com mais calma e atenção.

Compartilhar este post


Link para o post
Compartilhar em outros sites

sobre essa linha ai eu nem sei como fazer, so peguei de um tutor, e tentei adapta-la

 

 

<a href="relatorio.php?rel=bancoclaro&ID="<?php echo $ver['ID']; ?>" title="Gerar PDF" target="_self">Gerar PDF</a>

a pagina que ira gerar o pdf é a 2º ai, a relatorio.php...

 

eu faço umas consulta na 1º la, a cliente.php, e la que esta a variavel $ver, e queria que o que ela me desse la, ele me gererase um pdf, ai tentei jogar la... mais acho que esse link href ai que deve ter erro.. eu não sei como utilizar ele


no html ele me retorna a teble fazia

Compartilhar este post


Link para o post
Compartilhar em outros sites

Altere

 

?>
 
 
<a href="relatorio.php?rel=bancoclaro&ID="<?php echo $ver['ID']; ?>" title="Gerar PDF" 
target="_self">Gerar PDF</a>
 
<?php

 

por

 

?>
 
 
<a href="relatorio.php?rel=bancoclaro&ID=<?php echo $ver['ID']; ?>" title="Gerar PDF" 
target="_self">Gerar PDF</a>
 
<?php

 

A variável $ver só está disponível na página em que foi declarada, você não a declarou no arquivo relatorio.php.

 

Você tem que declarar, por exemplo:

 

 

<?php
$idVer = $_GET['ID'];
$ver = pegarVerPorId($idVer);
 
$html = "Aqui vai o resto do seu código na pagina relatorio.php...

 

está função é só um exemplo, você teria que fazer todo o processo de pegar um registro por id no banco de dados.

Compartilhar este post


Link para o post
Compartilhar em outros sites

mano, ta foda, não sei mais oque fazer..


ME RETORNOU TUDO 'S' .. ESTRANHO

 

$idVer = $_GET['ID'];
$ver = ('SELECT ID FROM bancoclaro WHERE ID =$idVer');

E DEI UM ECHO NO $html


não exporta ...

fica dando esse erro

 

:

Catchable fatal error: Argument 1 passed to DOMNode::appendChild() must be an instance of DOMNode, null given, called in C:\Program Files (x86)\VertrigoServ\www\BancoClaro\bkp\dompdf\include\table_frame_decorator.cls.php on line 320 and defined in C:\Program Files (x86)\VertrigoServ\www\BancoClaro\bkp\dompdf\include\frame.cls.php on line 440Call Stack#TimeMemoryFunctionLocation10.0005339264{main}( )..\relatorio.php:021.0208732264DOMPDF->render( )..\relatorio.php:8931.19294857336Frame_Decorator->reflow( )..\dompdf.cls.php:41741.19294857336Page_Frame_Reflower->reflow( )..\frame_decorator.cls.php:38751.19334858624Frame_Decorator->reflow( )..\page_frame_reflower.cls.php:7861.19334858624Block_Frame_Reflower->reflow( )..\frame_decorator.cls.php:38771.25886617968Frame_Decorator->reflow( )..\block_frame_reflower.cls.php:40881.25886617968Block_Frame_Reflower->reflow( )..\frame_decorator.cls.php:38791.26296627448Frame_Decorator->reflow( )..\block_frame_reflower.cls.php:408101.26296627448Table_Frame_Reflower->reflow( )..\frame_decorator.cls.php:387111.27036665752Frame_Decorator->reflow( )..\table_frame_reflower.cls.php:468121.27036665752Table_Row_Frame_Reflower->reflow( )..\frame_decorator.cls.php:387131.27056666352Frame_Decorator->reflow( )..\table_row_frame_reflower.cls.php:70141.27056666352Table_Cell_Frame_Reflower->reflow( )..\frame_decorator.cls.php:387151.27176668664Frame_Decorator->reflow( )..\table_cell_frame_reflower.cls.php:115161.27176668664Table_Frame_Reflower->reflow( )..\frame_decorator.cls.php:387171.27276670528Table_Frame_Reflower->get_min_max_width( )..\table_frame_reflower.cls.php:395181.27276670528Table_Frame_Decorator->normalise( )..\table_frame_reflower.cls.php:494191.27496677496Frame->append_child( )..\table_frame_decorator.cls.php:320

Compartilhar este post


Link para o post
Compartilhar em outros sites

Bom dia, estar dando erro no codigo HTML fica dando este erro

Catchable fatal error: Argument 1 passed to DOMNode::appendChild() must be an instance of DOMNode, null given, called in 

O CODIGO HTML PARA GERAR O PDF É ESSE

<?php
include('conexao.php');
$idVer = $_GET['ID'];
$ver = (" SELECT ID FROM bancoclaro WHERE ID ='$idVer' ");
?>
<?php
$html='
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CONSULTA CLARO</title>
</head>
<style type="text/css">
hr {
border: 2px solid #39F;
}
.textos {
font-family: Verdana, Geneva, sans-serif;
font-size: 18px;
line-height: 18px;
color: #020202;
}
td {
font-family: Verdana, Geneva, sans-serif;
font-size: 12px;
line-height: 18px;
color: #000000;
text-align: center;
}
body {
font-family: Calibri;
}
#dados {
font-family: Calibri;
font-size: 16px;
}
h2 {
font-family: Calibri;
color: #000000;
}
</style>
<body>
';


$html.='
<table width="870" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="406">Consulta Claro <span style="font-size: 18px"></span></td>
        <td width="251" align="right"><img src="exemplo.jpg" width="230" height="70"></tr>
    </tr>
</table>
<hr />
<h2>Ficha</h2>
<div id="dados">
<table width="870" border="1" cellpadding="1" cellspacing="0" id="listacliente">
<tr>
     <td height="44" colspan="5">
         <table width="865" border="1" cellpadding="8" cellspacing="0">
             <tr align="center" valign="middle">
                 <td width="152">Nome</td>
                    <td width="175">N°.Discado</td>
                    <td width="116">Hora</td>
                    <td width="213">Uf</td>
                    <td width="51">Valor</td>
                    <td width="55">Justificativa</td>
                </tr>
                 <td width="166">'.$ver['Usuario'].'</td>
                    <td width="195">'.$ver['NOMERO'].'</td>
                    <td width="126">'.$ver['HORA'].'</td>
                    <td width="227">'.$ver['UF'].'</td>
                    <td width="67">'.$ver['VALOR'].'</td>
            </table>
        </td>
    </tr>
</table>
</div>
<hr />
<p class="textos"> Clair Mont </p>


</body>
</html>
';
?>
<?php




//Aqui nós chamamos a class do dompdf
require_once('dompdf/dompdf_config.inc.php');


//É fundamental definir o TIMEZONE de nossa região para que não tenhamos problemas com a geração.
date_default_timezone_set('America/Sao_Paulo');


//Aqui eu estou decodificando o tipo de charset do documento, para evitar erros nos acentos das letras e etc.
$html = utf8_decode($html);


//Instanciamos a class do dompdf para o processo
$dompdf= new DOMPDF();


//Aqui nós damos um LOAD (carregamos) todos os nossos dados e formatações para geração do PDF
$dompdf->load_html($html);


//Aqui nós damos início ao processo de exportação (renderizar)
$dompdf->render();


//por final forçamos o download do documento, coloquei a nomenclatura com a data e mais um string no final.
$dompdf->stream(date('d/m/Y').'_cliente.pdf');
?>

EU NÃO CONSEGUIR ACHAR O ERRO, JA REFIZ O HTML E NADA, FICA DANDO SEMPRE ESSE ERRO.


conseguir resolver...

abrir mais uma

<tr align="center" valign="middle">

so que agora não esta me retornando nd, o pdf vem com as tabelas, a logo, mais vem sem os devidos conteudo do banco

 

$idVer = $_GET['ID'];
$ver = (" SELECT ID FROM bancoclaro WHERE ID = '$idVer' ");

Compartilhar este post


Link para o post
Compartilhar em outros sites

Não vem dados pq vc não buscou dados

 

Cade a consulta?

vc so fez isso

$idVer = $_GET['ID'];
$ver = (" SELECT ID FROM bancoclaro WHERE ID ='$idVer' ");
?>

cade o restante

Compartilhar este post


Link para o post
Compartilhar em outros sites

Quem foi que te ensinou que você faz uma consulta apenas com parênteses? isso não existe meu amigo.

 

O restantes NÃO fica na outra página, você vai ter que fazer tudo de novo. O que é tudo?: conectar ao banco de dados e retornar o resultado

 

Leia os seguintes links:

Compartilhar este post


Link para o post
Compartilhar em outros sites

fiz assim, mais parece que ele não cosegue pegar o ID, acho que é na hr que eu peço o link..

 

Ficou assim o codigo agora :

 

<?php
include('conexao.php');
$idVer = $_GET['ID'];
$consulta = (" SELECT * FROM bancoclaro WHERE ID = '$idVer' ");
$cosn = mysql_query($consulta);
if(mysql_num_rows($cosn) > 0){
while ($ver = mysql_fetch_array($cons)){
?>
<?php
$html='
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CONSULTA CLARO</title>


<style type="text/css">
hr {
border: 2px solid #F00;
}
.textos {
font-family: Verdana, Geneva, sans-serif;
font-size: 18px;
line-height: 18px;
color: #020202;
text-align: center;
}
td {
font-family: Verdana, Geneva, sans-serif;
font-size: 12px;
line-height: 18px;
color: #000000;
text-align: center;
}
body {
font-family: Calibri;
}
#dados {
font-family: Calibri;
font-size: 16px;
}
h2 {
font-family: Calibri;
color: #000000;
}
</style>
</head>
<body>
';


$html.='
<table width="798" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="406" style="text-align: center">Consulta Claro <span style="font-size: 25px"></span></td>
        <td width="251" align="right"><img src="LOGO-CM.png" width="230" height="70"></tr>
    </tr>
</table>
<hr />
<h2>Relatório</h2>
<div id="dados">
<table width="968" border="1" cellpadding="1" cellspacing="0" id="listacliente">
<tr>
     <td height="44" colspan="6">
         <table width="865" border="1" cellpadding="8" cellspacing="0">
             <tr align="center" valign="middle">
                 <td width="152">Nome</td>
                    <td width="175">N°.Discado</td>
                    <td width="116">Hora</td>
                    <td width="213">Uf</td>
                    <td width="51">Valor</td>
                    <td width="55">Justificativa</td>
                </tr>
<tr align="center" valign="middle">
                 <td width="166">'.$ver['Usuario'].'</td>
                    <td width="195">'.$ver['NOMERO'].'</td>
                    <td width="126">'.$ver['HORA'].'</td>
                    <td width="227">'.$ver['UF'].'</td>
                    <td width="67">'.$ver['VALOR'].'</td>
</tr>
            </table>
        </td>
    </tr>
</table>
</div>
<hr />
<p class="textos"> Clair Mont </p>


</body>
</html>
';}}
?>
<?php




//Aqui nós chamamos a class do dompdf
require_once('dompdf/dompdf_config.inc.php');


//É fundamental definir o TIMEZONE de nossa região para que não tenhamos problemas com a geração.
date_default_timezone_set('America/Sao_Paulo');


//Aqui eu estou decodificando o tipo de charset do documento, para evitar erros nos acentos das letras e etc.
$html = utf8_decode($html);


//Instanciamos a class do dompdf para o processo
$dompdf= new DOMPDF();


//Aqui nós damos um LOAD (carregamos) todos os nossos dados e formatações para geração do PDF
$dompdf->load_html($html);
$dompdf->set_paper('legal','landscape');
//Aqui nós damos início ao processo de exportação (renderizar)
$dompdf->render();
$dompdf->set_paper('legal','landscape');


//por final forçamos o download do documento, coloquei a nomenclatura com a data e mais um string no final.
$dompdf->stream(date('d/m/Y').'_cliente.pdf');
?>

e o da URL é esse, eu acho que o erro é nele, mais não sei como pegar o ID dela:

<a href="relatorio.php?rel=bancoclaro.ID=<?php echo $ver['ID']; ?>" title="Gerar PDF" 
target="_self">Gerar PDF</a>

eu coloquei pra da echo na $idver, e dar esse error :

( ! ) Notice: Undefined index: ID in C:\Program Files\VertrigoServ\www\claro\funcionando\bkp-pdf\Nova pasta\relatorio.php on line 3Call Stack#TimeMemoryFunctionLocation10.0186329800{main}( )..\relatorio.php:0

 

 

<?php
include('conexao.php');
$idVer = $_GET['ID'];
echo $idVer;
?>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Dê uma olhada neste tutorial que fiz algum tempo atrás veja se te ajuda:

 

http://forum.imasters.com.br/topic/489419-exportando-relatrio-para-pdf/

Compartilhar este post


Link para o post
Compartilhar em outros sites

Scali, deu na mesma mano...

 

Gabriel, eu to fazendo esse é baseado no seu tutorial msm, mais a variavel nao ta vindo mano...

ajuda ai..

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.