【问题标题】:laravel print a view without displaying it in browserlaravel 打印视图而不在浏览器中显示
【发布时间】:2015-02-12 10:06:46
【问题描述】:

在我的 laravel 项目中,我需要打印出医生的处方。为此,我已经创建了标题部分并保存在数据库中。当用户单击 div 旁边的打印机图标时,该 div 内的内容需要与保存的标题一起打印。

使用的方法是:在包含打印机图标的视图部分

<div class="AnswerBlock"><div class="NmaeDate">
            <span class="name"><?php echo 'Prescription :'; ?></span><span style="float:right;"><a href="<?php echo URL::to('/user/print-prescription',array($id,1));?>"><img src="<?php echo asset('images/footericons/printout.png'); ?>" title="prescription1" alt="take print" width="20" height="20"></a></span>

                   <div class="answer">
                       <?php echo stripslashes($data1->prescription1);?>
                   </div>
               </div>
            </div> 

在用户控制器中:

public function anyPrintPrescription($eid='',$no=''){

            $drpres='';
      $prs = DB::table('appoint')->where('id','=',$eid)->first();
      if($no=='1'){
       $drpres = $prs->prescription1;     
      }
      elseif($no=='2'){
          $drpres= $prs->prescription2;
      }
      elseif($no=='3'){
          $drpres = $prs->prescription3;
      }
      $presheader = Admin::where('id','=',$prs->d_id)->pluck('prescription_header');
      return View::make('con.printout_prescription')->with(array('presc'=>$drpres,'phead'=>$presheader));  

   }

视图是:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style type="text/css">
.print:last-child {
 page-break-after: auto;
 }
</style>

</head>
<body onload="window.print()">
<div class="print"><?php echo $phead;?></div>
<div class="print"><?php echo $presc;?></div>
</body>
</html>

我得到的输出是:单击打印图标时,打印机选项提示窗口正在打开。但同时浏览器会转到查看 url 并显示它。

有谁知道如何让窗口不显示视图?

【问题讨论】:

    标签: php laravel printing


    【解决方案1】:

    这不是一个真正的 Laravel 甚至 PHP 问题,而是一个浏览器能做什么和不能做什么的问题。

    浏览器不查看就无法打印。我唯一可以建议的是在新窗口或选项卡中打开视图(更改回调视图的代码)并在打印完成后将其关闭。

    【讨论】:

    • 好的..谢谢你的建议。我已经使用 window.onfocus 实现了它并工作了
    猜你喜欢
    • 2016-02-28
    • 2015-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-27
    • 2013-07-31
    • 2011-08-14
    相关资源
    最近更新 更多