Print specific div using jquery

  • 3 years-4 months

    Print specific div using jquery

    • Category : jquery
    • Viewed : 136 times
    • Posted On :
    • Posted by : Guley

    You can print specific div or area using this script

    /******Html*********/
     <a href="javascript:void(0);" id="printinvoice"  class="btn btn-warning btn-sm">PRINT INVOICE</a>
    
    <div class="print_div">
                        <div class="col-xs-6 table-responsive">
                            <div class = "sales_header">
                                <span>ORDER NO: # 11380189</span>  
                            </div>
                            <table class="table table-striped table-bordered datatables dataTable">
                                <tbody>
                                    <tr>
                                        <td>Order date</td>
                                        <td>12 Apr 2017 15:55:34</td>
                                    </tr>
                                    <tr>
                                        <td>Order Status</td>
                                        <td> Processed                                    </td>
                                    </tr>
                                    <tr>
                                        <td>Currency</td>
                                        <td>GBP</td>
                                    </tr> 
                                </tbody>
                            </table>
                        </div>  
     </div> 
    /***script**/
    <script src="/assets/js/jQuery.print.js"></script>
    $(document).ready(function() {
        $(document).on('click','#printinvoice',function(){
            //Print ele4 with custom options
            $('.print_div').print({
                //Use Global styles
                globalStyles: true,
                //Add link with attrbute media=print
                mediaPrint: true,
                //Custom stylesheet
                stylesheet: "http://fonts.googleapis.com/css?family=Inconsolata",
                //Print in a hidden iframe
                iframe: true,
                //Don't print this
                noPrintSelector: ""
            });
        });
    });

Report this or Ask your own question

Your Answer

When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.