问题
I am trying to to take the print out of a page using php. I can do it in Javascript. But would like to do it using PHP. Is there any way to do other than using Javascript
回答1:
No. Printing a page is a function of the browser, so you have to use code that's running in the browser. That means Javascript only, not PHP.
回答2:
<?php error_reporting(0);
include('config.php');
$ftch="SELECT * FROM tb_patient_info WHERE patient_id='9'";
$ftch_row=mysql_fetch_array(mysql_query($ftch));
$ink=base64_encode(file_get_contents('patient_image/'.$img));
?>
<script type="text/javascript">
function CallPrint(strid)
{
var printContent = document.getElementById(strid);
var windowUrl = 'about:blank';
var uniqueName = new Date();
var windowName = 'Print' + uniqueName.getTime();
var printWindow = window.open(windowUrl, windowName, 'left=50000,top=50000,width=800,height=600');
printWindow.document.body.innerHTML = printContent.innerHTML;
printWindow.document.close();
printWindow.focus();
printWindow.print();
printWindow.close();
return false;
}
<?php $content= '<table style="width:450px; color:#00000; margin:22px 0 0 0px; font-family:Helvetica, sans-serif, Verdana; font-size:15px; border1px solid #666;">
<tr><td style=" width:200px;"> Email:</td> <td style=" width:250px;">' . $ftch_row['patient_name']. '</td></tr>
</table>'
?>
<div style="width:655px; height:250px;" id="printArea"><div style="width:450px; height:250px; float:left;" > <?php echo $content; ?></div><div style="width:150px; height:150px; border:5px solid #999; float:left; margin:50px 0 0 0;" ><img src="data:image/jpg;base64,<?php echo $ink;?>" height="150" width="150"/></div></div>
<div style=" height:20px; width:60px; margin:0 0 0 550px;"><input name="print" type="button" value="Print" onclick="CallPrint('printArea')" /></div>
!This is a print page image]1
来源:https://stackoverflow.com/questions/8207293/how-to-take-the-print-out-of-a-page-using-php