This question may be simple. But i couldnt achieve this. I am using a library called print.js. Using that i am printing a html div from browser.i will use this webpage in an android tab. I have 2 issues.
- I wish to print 2 copies of the same in single event
- I wish to send the print request directly to printer without a print preview
Can i achieve this
About the 1st option, the library doesn't support duplicating the html element when dispatching the print job. Its quite an edge case. You can however manipulate your html code creating a hidden printable element in your code, and then send the hidden element to the lib. Make sure you send a print media query with it so the lib can display the element when dispatching the print job.
Here is a sandbox showing and example on how to print hidden elements: https://codesandbox.io/s/printjs-styled-html-l0yk8?file=/index.html
With this, you can customize any print job in anyway you want, without affecting the UI.
About the 2nd option, you cannot bypass the user preview or settings screen with JavaScript alone. That would be a security issue. Imagine opening a website and your printer start to print stuff automatically, that wouldn't be nice.