Cleimar Lemes Postado 19 horas atrás Denunciar Share Postado 19 horas atrás etiqueta.php <?php // DEFINE O FUSO HORARIO COMO O HORARIO DE BRASILIA date_default_timezone_set('America/Sao_Paulo'); ?> <html> <html lang="pt-br"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Etiquetas dos Cadastros</title> <meta http-equiv="Content-Type" content="charset=utf-8" /> <link href='https://fonts.googleapis.com/css?family=Barlow&subset=latin-ext' rel='stylesheet'> <style> body { font-family: 'Barlow'; font-size: 14px; } @page{ margin: 150px 50px ; } body{ font-family: 'Verdana', sans-serif; margin:0px; padding:0px; } .header{ position: fixed; left: 0; right:0; top: -100px; height: 50px; padding: 10px; background: #333; margin-bottom:100px; text-align: center; } .header img{ height: 50px; } .footer{ position: fixed; left: 0; right:0; bottom:0; background: #333; color:#FFF; text-align: center; padding: 10px; } h1{ text-align: center; } table{ width: 100%; border:1px solid #000000ff; padding: 5px; } table tr th{ background: #1b1916ff; color:#FFF; padding:5px; } table tr:nth-child(even) td{ background: #EEE; } .image{ text-align: center; } .image img{ border: 1px solid #CCC; padding:3px; margin:5px; } </style> <p><button type="button" onclick="window.open(href='geraetiqueta.php', 'popup', 'fullscreen=1, height=680px, width=900px')">GERAR PDF</button ></p> </head> <body> <header class="header"> <img src="https://cdn.iconscout.com/icon/premium/png-256-thumb/dev-environment-icon-svg-png-download-3272349.png" alt="" height="50"> </header> <h1>Etiquetas de Cadastros</h1> <?php include('conexao.php'); $sql = "SELECT * FROM tb_cadastro"; $res = $conn->query($sql); if($res->num_rows > 0){ $html = "<table border='1'>"; while($row = $res->fetch_object()){ $html .= "<tr>"; //$html .= "<th>Id</th>"; $html .= "<th>Matrícula</th>"; $html .= "<th>Nome</th>"; $html .= "<th>Tipo</th>"; //$html .= "<th>Placa</th>"; //$html .= "<th>Veículo</th>"; //$html .= "<th>Cidade</th>"; //$html .= "<th>Uf</th>"; //$html .= "<th>Empresa</th>"; //$html .= "<th>Data</th>"; //$html .= "<th>Entrada</th>"; //$html .= "<th>Saída</th>"; $html .= "</tr>"; $html .= "<tr>"; //$html .= "<td>$row->id</b></td>"; $html .= "<td>$row->matricula</b></td>"; $html .= "<td>$row->nome</b></td>"; $html .= "<td>$row->tipo</b></td>"; //$html .= "<td>$row->placa</b></td>"; //$html .= "<td>$row->veiculo</b></td>"; //$html .= "<td>$row->cidade</b></td>"; //$html .= "<td>$row->uf</b></td>"; //$html .= "<td>$row->empresa</b></td>"; //$html .= "<td>$row->dataentrada</b></td>"; //$html .= "<td>$row->horaentrada</b></td>"; //$html .= "<td>$row->horasaida</td>"; $html .= "</tr>"; } $html .= "</table>"; }else{ $html .= 'Nenhum dado recebido'; } // print $html; echo $html; ?> <footer class="footer"> Gerado em <?php echo (new DateTime())->format('d/m/Y H:i:s')?> </footer> </body> </html> conexao.php <?php $servidor = "localhost"; $usuario = "root"; $senha = ""; $dbname = "polo"; //Criar a conexao $conn = mysqli_connect($servidor, $usuario, $senha, $dbname); if(!$conn){ die("Falha na conexao: " . mysqli_connect_error()); }else{ //echo "Conexao realizada com sucesso"; } ?> geraetiqueta.php <?php // DEFINE O FUSO HORARIO COMO O HORARIO DE BRASILIA date_default_timezone_set('America/Sao_Paulo'); require __DIR__ . '/vendor/autoload.php'; use Dompdf\Dompdf; $dompdf = new Dompdf(); ob_start(); // include 'etiqueta.php'; // $html=ob_get_clean(); // $dompdf->loadHtml($html); $dompdf->setPaper('A4', 'portrait'); $dompdf->render(); $output = $dompdf->output(); file_put_contents("./tmp/etiqueta.pdf", $output); die("<script>location.href='./tmp/etiqueta.pdf';</script>"); ?> Citar Link para o comentário Compartilhar em outros sites More sharing options...
0 Frank K Hosaka Postado 18 horas atrás Denunciar Share Postado 18 horas atrás 1 não pode usar o marcador html duas vezes 2 é proibido colocar o botão de comando dentro do <head> 3 você quebrou um monte de célula <td></b></td> 4 precisa ter a pasta temp no diretório do projeto Eu simplifiquei conexao.php e etiqueta.php assim: <?php date_default_timezone_set('America/Sao_Paulo'); ?> <!DOCTYPE html> <html lang="pt-br"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Etiquetas dos Cadastros</title> <meta http-equiv="Content-Type" content="charset=utf-8" /> </head> <body> <p><button type="button" onclick="window.open(href='geraetiqueta.php', 'popup', 'fullscreen=1, height=680px, width=900px')">GERAR PDF</button ></p> <h1>Etiquetas de Cadastros</h1> <?php $mysqli=new mysqli("localhost","root","","polo"); $res=$mysqli->query("select * from tb_cadastro"); if($res->num_rows > 0) : ?> <table border='1'> <?php while($row = $res->fetch_object()) : ?> <tr> <th>Matrícula</th> <th>Nome</th> <th>Tipo</th> </tr> <tr> <td><?=$row->matricula?></td> <td><?=$row->nome?></td> <td><?=$row->tipo?></td> </tr> </table> <?php endwhile; else: echo 'Nenhum dado recebido'; endif ?> </body> </html> Citar Link para o comentário Compartilhar em outros sites More sharing options...
0 Cleimar Lemes Postado 17 horas atrás Autor Denunciar Share Postado 17 horas atrás 33 minutos atrás, Frank K Hosaka disse: 1 não pode usar o marcador html duas vezes 2 é proibido colocar o botão de comando dentro do <head> 3 você quebrou um monte de célula <td></b></td> 4 precisa ter a pasta temp no diretório do projeto Eu simplifiquei conexao.php e etiqueta.php assim: <?php date_default_timezone_set('America/Sao_Paulo'); ?> <!DOCTYPE html> <html lang="pt-br"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Etiquetas dos Cadastros</title> <meta http-equiv="Content-Type" content="charset=utf-8" /> </head> <body> <p><button type="button" onclick="window.open(href='geraetiqueta.php', 'popup', 'fullscreen=1, height=680px, width=900px')">GERAR PDF</button ></p> <h1>Etiquetas de Cadastros</h1> <?php $mysqli=new mysqli("localhost","root","","polo"); $res=$mysqli->query("select * from tb_cadastro"); if($res->num_rows > 0) : ?> <table border='1'> <?php while($row = $res->fetch_object()) : ?> <tr> <th>Matrícula</th> <th>Nome</th> <th>Tipo</th> </tr> <tr> <td><?=$row->matricula?></td> <td><?=$row->nome?></td> <td><?=$row->tipo?></td> </tr> </table> <?php endwhile; else: echo 'Nenhum dado recebido'; endif ?> </body> </html> obrigado por sua dica. assim vou aprendendo.. agora to querendo apresentar a foto antes da matricula.. mas so aparece um quadrado.. a pasta temp já tem no diretorio.. Agora, Cleimar Lemes disse: obrigado por sua dica. assim vou aprendendo.. agora to querendo apresentar a foto antes da matricula.. mas so aparece um quadrado.. a pasta temp já tem no diretorio.. Citar Link para o comentário Compartilhar em outros sites More sharing options...
0 Frank K Hosaka Postado 15 horas atrás Denunciar Share Postado 15 horas atrás (editado) Esse deu trabalho, tive que mexer na etiqueta.php e no geraetiqueta.php, a foto coloquei na pasta fotos, e no campo foto coloquei coisa do tipo fotos/foto1.webp: etiqueta.php <?php date_default_timezone_set('America/Sao_Paulo'); ?> <!DOCTYPE html> <html lang="pt-br"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Etiquetas dos Cadastros</title> <meta http-equiv="Content-Type" content="charset=utf-8" /> </head> <body> <p><button type="button" onclick="window.open(href='geraetiqueta.php', 'popup', 'fullscreen=1, height=680px, width=900px')">GERAR PDF</button ></p> <h1>Etiquetas de Cadastros</h1> <?php $mysqli=new mysqli("localhost","root","","polo"); $res=$mysqli->query("select * from tb_cadastro"); if($res->num_rows > 0) : ?> <table border='1'> <?php while($row = $res->fetch_object()) : ?> <tr> <th>Foto</th> <th>Matrícula</th> <th>Nome</th> <th>Tipo</th> </tr> <tr> <?php $path = __DIR__ . "/" . $row->foto; $type = mime_content_type($path); $data = base64_encode(file_get_contents($path)); $src = "data:$type;base64,$data"; ?> <td><img src="<?= $src ?>" width="100" /></td> <td><?=$row->matricula?></td> <td><?=$row->nome?></td> <td><?=$row->tipo?></td> </tr> </table> <?php endwhile; else: echo 'Nenhum dado recebido'; endif ?> </body> </html> geraetiqueta.php <?php require __DIR__ . '/vendor/autoload.php'; use Dompdf\Dompdf; use Dompdf\Options; $options = new Options(); ob_start(); include 'etiqueta.php'; $html=ob_get_clean(); $options->setIsRemoteEnabled(true); $dompdf = new Dompdf($options); $dompdf->loadHtml($html); $dompdf->setPaper('A4', 'portrait'); $dompdf->render(); $output = $dompdf->output(); file_put_contents("./tmp/etiqueta.pdf", $output); die("<script>location.href='./tmp/etiqueta.pdf';</script>"); ?> Editado 15 horas atrás por Frank K Hosaka Citar Link para o comentário Compartilhar em outros sites More sharing options...
0 Cleimar Lemes Postado 2 horas atrás Autor Denunciar Share Postado 2 horas atrás 13 horas atrás, Frank K Hosaka disse: Esse deu trabalho, tive que mexer na etiqueta.php e no geraetiqueta.php, a foto coloquei na pasta fotos, e no campo foto coloquei coisa do tipo fotos/foto1.webp: etiqueta.php <?php date_default_timezone_set('America/Sao_Paulo'); ?> <!DOCTYPE html> <html lang="pt-br"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Etiquetas dos Cadastros</title> <meta http-equiv="Content-Type" content="charset=utf-8" /> </head> <body> <p><button type="button" onclick="window.open(href='geraetiqueta.php', 'popup', 'fullscreen=1, height=680px, width=900px')">GERAR PDF</button ></p> <h1>Etiquetas de Cadastros</h1> <?php $mysqli=new mysqli("localhost","root","","polo"); $res=$mysqli->query("select * from tb_cadastro"); if($res->num_rows > 0) : ?> <table border='1'> <?php while($row = $res->fetch_object()) : ?> <tr> <th>Foto</th> <th>Matrícula</th> <th>Nome</th> <th>Tipo</th> </tr> <tr> <?php $path = __DIR__ . "/" . $row->foto; $type = mime_content_type($path); $data = base64_encode(file_get_contents($path)); $src = "data:$type;base64,$data"; ?> <td><img src="<?= $src ?>" width="100" /></td> <td><?=$row->matricula?></td> <td><?=$row->nome?></td> <td><?=$row->tipo?></td> </tr> </table> <?php endwhile; else: echo 'Nenhum dado recebido'; endif ?> </body> </html> geraetiqueta.php <?php require __DIR__ . '/vendor/autoload.php'; use Dompdf\Dompdf; use Dompdf\Options; $options = new Options(); ob_start(); include 'etiqueta.php'; $html=ob_get_clean(); $options->setIsRemoteEnabled(true); $dompdf = new Dompdf($options); $dompdf->loadHtml($html); $dompdf->setPaper('A4', 'portrait'); $dompdf->render(); $output = $dompdf->output(); file_put_contents("./tmp/etiqueta.pdf", $output); die("<script>location.href='./tmp/etiqueta.pdf';</script>"); ?> cara tu e bom em.. vou estudar o codigo e ver onde eu tva errando kkkkkkkkk mas com certeza tem muita diferença.. valeu 👍 5 minutos atrás, Cleimar Lemes disse: cara tu e bom em.. vou estudar o codigo e ver onde eu tva errando kkkkkkkkk mas com certeza tem muita diferença.. valeu 👍 so copiei e colei o seu e o meu deu erro kkkkkkkk tem a pasta fotos e tem a pasta tmp ae ele da como se não tivesse encontrado a pasta ou as fotos.. olha.. Citar Link para o comentário Compartilhar em outros sites More sharing options...
0 Frank K Hosaka Postado 49 minutos atrás Denunciar Share Postado 49 minutos atrás (editado) Hahahaha... eu também tive essa dor de cabeça, mas se você prestar atenção na mensagem de erro, dá para ver que ele está procurando a foto no lugar errado. A foto não está na pasta polo, e sim na pasta polo/fotos/. Reveja o seu código, ele não contempla o subdiretório fotos no diretório polo. No meu caso, eu cadastrei o endereço do arquivo dentro do banco de dados, na tb_cadastro, no campo foto, assim: fotos/foto1.webp (veja se esse arquivo existe com o mesmo nome através do gerenciador de arquivos do Windows! qualquer letra errada, tudo dá errado). No meu caso, precisei acrescentar "\" no código. Eu faço de um jeito, e faz de outro jeito, e depois coloca a culpa em mim. Isso sim está errado!!! Hahahahaha... Editado 39 minutos atrás por Frank K Hosaka Citar Link para o comentário Compartilhar em outros sites More sharing options...
Pergunta
Cleimar Lemes
Link para o comentário
Compartilhar em outros sites
5 respostass a esta questão
Posts Recomendados
Participe da discussão
Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.