Как вывести распечатку страницы с помощью php? - PullRequest
0 голосов
/ 21 ноября 2011

Я пытаюсь распечатать страницу, используя php. Я могу сделать это в Javascript. Но хотел бы сделать это с помощью PHP. Есть ли способ сделать кроме использования Javascript

Ответы [ 2 ]

1 голос
/ 21 ноября 2011

Нет.Печать страницы является функцией браузера, поэтому вы должны использовать код, который работает в браузере.Это означает только Javascript, а не PHP.

0 голосов
/ 15 января 2014
   <?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>

! Это изображение страницы печати] 1

...