Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
247 views
in Technique[技术] by (71.8m points)

javascript - invoice print without preview click and direct print?

I have need without print preview invoice ? i am share all code (normal work is fine with preview) but no need preview and no need print dialog box so please share any one valuable idea please. i am using javascript and codeigniter all is well but need print preview dialog box.all work responce fine so please check and help me...

javascript

 <script type="text/javascript">
           function print_booking()
              {
                 var val     =$('#get_ref_by').val();
                
                 if(!val){alert("Patient id  empty!");}
                 
                  else{ 
                  $.ajax({
                  url: "<?php echo base_url(); ?>print_booking_latter",
                  type: "post",
                  data: "val="+val,
                  success: function (response)
                      {
                      var global_res = JSON.parse(response);
                      console.log(global_res);
                       /*================================*/
                          var win = "";
                              win = '<!doctype html>';
                              win+='<html lang="en">';
                              win+='<head>';
                              win+='<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">';
                              win+='<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">';
                              win+='<meta charset="UTF-8">';
                              win+='<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">';
                              win+='<meta http-equiv="X-UA-Compatible" content="ie=edge">';
                              win+='<title>PRIC</title>';
                              win+='<style type="text/css" media="print">.page-header, .page-header-space {height: 100px;}.page-footer, .page-footer-space {height: 70px;}';
                       
                              win+='.page-footer {'+
                                  'position: fixed;'+
                                  'bottom: 0;'+
                                  'width: 100%;'+
                                  'border-top: 1px solid black; /* for demo */'+
                                  'background: yellow; /* for demo */'+
                                  '}'+
                                  '.page-header {'+
                                  'position: fixed;'+
                                  'top: 0mm;'+
                                  'width: 100%;'+
                                  'border-bottom: 1px solid black; /* for demo */'+
                                  'background: yellow; /* for demo */}'+
                                   
                                   'page[size="A4"][layout="portrait"]{width: 29.7cm; height: 21cm;}'+
        
                                  '.table-bordered td, .table-bordered th,tabel{'+
                                  ' border: 0px!important;}'+
                                  
                                  '.table-bordered tr, .table-bordered tr{'+
                                  ' border: 1px solid #dee2e6!important;}'+
                                  
                                  '.page {'+
                                  'page-break-after: always;}'+
                       
                                  '@page {margin: 2mm}'+
                       
                                  '@media print {'+
                                  'thead {display: table-header-group;}'+
                                  'tfoot {display: table-footer-group;}'+
                                  'td, th {font-size: 12px}'+
                                  'button {display: none;}'+
                                  'p{font-size: 10px}'+
                                  'body {margin: 0;}}'+
                                  'tfoot {display: table-header-group;}'+
                       
                                  '</style>'+
                                  '</head>'+
                                  '<body>';
                               //=============top title========================
                         
                           win+='<div class="container-fluid" style="margin-bottom:50px;">';
                           win+='<div class="row">';
                           win+='<div class="col-md-12 text-center">';
                           win+='<img  style="width:12%;" src="<?php echo base_url();?>assets/doctor/img/logo_small.png">';
                           win+='<h3>Punjab Rheumatology & Immunology Centre</h3>';
                           win+='</div>';
                           win+='</div>';
                           
                           win+='<div class="row">';
                           win+='<div class="col-md-3">';
                           win+='<h5>Dr. Parshant Aggarwal</h5>';
                           win+='<p>MD DM (Immunology)</br>Consultant Rheumatologist & Immunologist</br>Ex Consultant Apollo Hospital, LDH</br>Ex Asstt Prof DMC & H.LDH</br>Regn No. PMC 29517</p>';
                           win+='</div>';
                           
                           win+='<div class="col-md-6"></div>';
                           
                           win+='<div class="col-md-3">';
                           win+='<h5>Dr. Bharti Aggarwal</h5>';
                           win+='<p>MD DM (Medicine) PDCC (Infections)</br>EULAR Rheumatology Fellow</br>Consultant Rheumatologist & Physician</br>Ex Asstt Prof DMC & H.LDH</br>Regn No. PMC 31277</p>';
                           win+='</div>';        
                           win+='</div><hr>';
                           
                           win+='<div class="row">';
                           win+='<div class="col-md-12">';
                           win+='<p>Dated : <b> <?=$today_date;?> </b> </p>';
                           win+='</div>';
                           win+='</div>';
                           
                           win+='<div class="row">';
                           win+='<div class="col-md-12">';
                           win+='<p>Dear <em> '+global_res[0]['ref_name']+'&nbsp;('+global_res[0]['ref_address']+') </em> </p>';
                           win+='<p><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Thank for referring  '+global_res[0]['name']+'&nbsp;'+global_res[0]['gender']+'&nbsp;Punjab Rheumatology & Immunology Clinic, The patient has been diagnosed as suffering from SLE (phosensitivity, oral ulcers, pancreatitis, CNS, ANA), OCD, migraine.</em> </p>';
                           win+='<p><em>Your suggestions & feedback are important for us, please feel free to our [email protected], You can also contact me at my personal number 9876702493 Dr Parshant 9876875444 Dr Bharti. For scheduling an appointment patients can contact 9814267774, 9878736644, Looking forward to your continued support & feedback in our endeavor to limit suffering from Rheumatic & Immunological disorders.</em></p>';
                           win+='</div>';
                           win+='</div>';
                           
                           win+='<div class="row">';
                           win+='<div class="col-md-12">';
                           win+='<p><b>With sincere regards, </b></p>';
                           win+='</div>';
                           win+='</div>';
                           
                           win+='<div class="row">';
                           win+='<div class="col-md-6">';
                           win+='<p><b>Dr. Parshant Aggarwal</b></p>';
                           win+='</div>';
                           win+='<div class="col-md-6" style="text-align:right">';
                           win+='<p><b>Dr. Bharti Aggarwal</b></p>';
                           win+='</div>';
                           win+='</div>';
                        
                           //====================footer--------------------------
                                win+='<div class="col-md-12 text-center" style="position:fixed;left: 0;bottom: 0;width: 100%;text-align: center;">';
                                win+='<p style="style="font-size:12px;font-weight:500;">';
                                win+='Main  Ferozepur Road, Near MBD Mall, Rajguru Nagar , Ludhiana (PB)';
                                win+='</br>';
                                win+='Consultation by Appointment Only | Dial 98787-36644, 98142-67774';
                                win+='</hr>';
                                win+='Email: [email protected] | www.punjabrheumatology.com';
                                win+='</br>';
                                win+='Advice given without physical checkup, on phone, Email, Social media etc is provisional & subject to Physical Examination by';
                                win+='</br>';
                                win+='qualified specialist at the earliest . Patient Can  Buy Generic Medicine of Same Salt.';
                                win+='</p>';
                           
                           win+='</div>';
                           win+='</body>';
                           win+='</html>';
]
                              win_disp = window.open('', '', 'height=500,width=900');
                              win_disp.document.write(win);
                              win_disp.focus();
                              $(win_disp).find('body').attr('onload', 'window.print();');
                              setTimeout(function() {
                                  win_disp.print();
                              }, 900)

                      }
                  });
                }
                
              }
        </script>
question from:https://stackoverflow.com/questions/65936667/invoice-print-without-preview-click-and-direct-print

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can try with iframe:-

function printThis() {

    var content = "Your contents";

    $('<iframe>', {
        name : 'myiframe',
        id   : 'printFrame',
        style: 'display:none'
    })
    .appendTo('body')
    .contents().find('body')
    .append(content);

    setTimeout(() => { 
        window.frames['myiframe'].focus();
        window.frames['myiframe'].print(); 
        var frame = document.getElementById("printFrame");
        frame.parentNode.removeChild(frame);
    }, 200); 

}
<button type="button" onclick="printThis()">Print This</button>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...