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.

4
  • 1
    Unclear what you want to a happen.... Commented Mar 17, 2017 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(). Commented Mar 17, 2017 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. Commented Mar 17, 2017 at 19:45
  • This is as close as you are going to get stackoverflow.com/questions/16456717/… Commented Mar 17, 2017 at 19:48

3 Answers 3

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();
}
Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

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()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.