1

I have some values in my screen , i need to print(through printer) only values in the screen by using JavaScript or j query , Is there is any inbuilt function ? except print();

Thanks as advance.

  • 1
    Unclear what you want to a happen.... – epascarello Mar 17 '17 at 19:37
  • I don't think there's any way for Javascript to send to the printer directly. The only method is `window.print()`. – Barmar Mar 17 '17 at 19:39
  • also, the javascript print() function actually has nothing to do with printing to paper - it simply writes additional text to the HTML of the currently loaded page. – Joe Irby Mar 17 '17 at 19:45
  • This is as close as you are going to get http://stackoverflow.com/questions/16456717/how-can-i-print-using-jquery – Cesar Bielich Mar 17 '17 at 19:48

3 Answers3

1

There is no way to print some data directly, but you can use a work around method to do it
Try this function

function print_specific_content() {
    var content = "Printed using Ahmed El-Essawy Code";

    var win = window.open('', '', 'left=0,top=0,width=800,height=800,toolbar=0,scrollbars=0,status =0');
    win.document.write("<html><body onload=\"window.print(); window.close();\">" + content + "</body></html>");
    win.document.close();
}
Ahmed Essawy
  • 326
  • 4
  • 13
0

AFAIU you want to SEND values to printer. If it's not the case please report back.

Javascript is traditionally a client-side language, so you don't have direct access to hardware. However with the advent of server javascript libraries (like Node.js) you do have server modules (as node-printer) that allow you to print things (like the examples in this answer: Node.js : How to add print job to printer)

So you would have to have a Node.js module that do the printing you want, and you would have to call it with and ajax function or something to print the values.

Hope I clarified.

Community
  • 1
  • 1
Nelson Teixeira
  • 6,297
  • 5
  • 36
  • 73
0

You can print your specific text from the web page by using CSS @media print

Here is an example :

HTML:

<body>
  <div class="doNotPrint"></div>
  <div class="printThisSection">
    <!-- HERE IS THE HTML CODES FOR PRINT-->
  </div>
  <div class="doNotPrint"></div>
</body>

CSS :

@media print{
  .doNotPrint{ /*This section will never print*/
    display: none;
  }
  /*Your other CSS property here*/
}

Note : You can use shortcut ctrl + p to show print popup instead of using window.print()

Sumon Sarker
  • 2,707
  • 1
  • 23
  • 36