Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
183
rated 0 times [  190] [ 7]  / answers: 1 / hits: 16438  / 12 Years ago, thu, december 13, 2012, 12:00:00

I have a HTML content in a variable like this.



$message =<div>
<table align='center'>
<tr><td><h1>Reporte de Tipo de Documentos</h1></td></tr>
<tr><td><h2>Farmaceutica MDC</h2></td></tr>
</table>
</div>
<div>
<table style='width:960px; margin:0 auto;'>
<tr colspan='7'>
<td><?php echo 'Fecha: '.$time = date('d/m/Y h:i:s A').; ?></td>
</tr>
<tr bgcolor='#CCCCCC' height='30'>
<td><b>Sr. No.</b></td>
<td><b>Tipo Documento</b></td>
<td><b>Cant. Pasos</b></td>
<td><b>Costo</b></td>
<td><b>Precio</b></td>
<td><b>Balance</b></td>
<td><b>Notifica Cliente</b></td>
</tr>
</table>;


I want to print a printout page of this HTML Content.
Like for web page we use



<script type=text/javascript>
function printpage()
{

window.print();

}
</script>.


So what i use to print the above HTML content?


More From » php

 Answers
2

How about embedding the contents of this page in HTML and adding a script to print it out automatically on page load?



<?php
$message =<div>
<table align='center'>
<tr><td><h1>Reporte de Tipo de Documentos</h1></td></tr>
<tr><td><h2>Farmaceutica MDC</h2></td></tr>
</table>
</div>
<div>
<table style='width:960px; margin:0 auto;'>
<tr colspan='7'>
<td><?php echo 'Fecha: '.$time = date('d/m/Y h:i:s A').; ?></td>
</tr>
<tr bgcolor='#CCCCCC' height='30'>
<td><b>Sr. No.</b></td>
<td><b>Tipo Documento</b></td>
<td><b>Cant. Pasos</b></td>
<td><b>Costo</b></td>
<td><b>Precio</b></td>
<td><b>Balance</b></td>
<td><b>Notifica Cliente</b></td>
</tr>
</table>;

echo <html><head></head><body> . $message . <script type='application/javascript'>window.onload=function(){window.print()}</script></body></html>;
?>


To literally print the HTML code, you can sanitize the HTML like:



echo <html><head></head><body> . htmlspecialchars($message, ENT_QUOTES) . <script type='application/javascript'>window.onload=function(){window.print()}</script></body></html>;
?>


More information about this:




[#81448] Wednesday, December 12, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
devinjadong

Total Points: 711
Total Questions: 117
Total Answers: 100

Location: Andorra
Member since Sat, May 27, 2023
1 Year ago
devinjadong questions
Thu, Feb 17, 22, 00:00, 2 Years ago
Wed, Dec 8, 21, 00:00, 2 Years ago
Tue, Oct 27, 20, 00:00, 4 Years ago
Fri, Oct 18, 19, 00:00, 5 Years ago
;