I use java script to print only the contents of a div, but I do not need to use the browser print dialog box.
Reason: I created a formatting for the text, when it goes to print by the dialog box is losing my formatting.
How could I get this right?
Here are my codes:
DIV:
<style type="text/css">
body {
width:100px;
}
#div1{
border:solid 1px;
box-shadow: 10px 10px 10px 5px black;
font-size: 8px;
font-weight: bold;
font-family: Arial;
}
</style>
JS:
<script>
function cont(){
var conteudo = document.getElementById('print').innerHTML;
tela_impressao = window.open('about:blank');
tela_impressao.document.write(conteudo);
tela_impressao.window.print();
tela_impressao.window.close();
}
</script>
CONTENT:
<div class="container">
<div class="row">
<div id="div1" style="width:400px; margin:0 auto;">
<?php
echo"<div id='print' class='conteudo'>";
echo"<center><img src='logo.png' width='200';margin:0 auto;></center>";
echo"<center><b>COMPROVANTE DE TROCA DE VASILHAME</center></b>";
echo"<hr>";
echo "<p>COMPROVANTE N°: $v_cupom </p>";
echo "<p>LOJA: $v_loja_num - $v_loja_desc </p>";
echo "<p>VASILHAME: $v_cod_ean - $v_vasilhame </p>";
echo "QUANTIDADE: $v_quantidade";
echo"<hr>";
echo"<center>DATA: $v_data HORA: $v_hora </center>";
echo "</div>";
?>
</div>
</div>
<br>
<center><a href="index.php" class="btn btn-danger" onclick="cont();" value="Imprimir">IMPRIMIR</a></center>
<br>
</div>
</div>