Cleimar Lemes Postado 10 horas atrás Denunciar Share Postado 10 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 9 horas atrás Denunciar Share Postado 9 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 8 horas atrás Autor Denunciar Share Postado 8 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 7 horas atrás Denunciar Share Postado 7 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 7 horas 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
3 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.