0

I'm a newbie with JavaScript and I was looking for a method to print a pdf document with a button click without any dialog window opening or not make the user able to change the print settings, I want to print it with a fixed printer, number of pages and format.

I already tried Print.js but it still opens a dialog window and the user can change the settings in it.

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
Cris
  • 21
  • 2
  • Does this answer your question? [Print PDF directly from JavaScript](https://stackoverflow.com/questions/16239513/print-pdf-directly-from-javascript) – Heretic Monkey Oct 07 '21 at 20:25
  • 2
    **TLDR:** It's not possible. That would pose a serious security risk. – War10ck Oct 07 '21 at 20:25
  • 1
    Due to security concerns, browsers will not allow you you to print without consent. Or saving without consent. If the browser has the settings to download without a popup window, then you might be able to locally create a file on the server side and then saving it. Also, a while back I had a similar issue, but I needed it to be local on one system only. So I created a simple C# program to create a document, save it as PDF, open it in Adobe Reader (hidden window), and sent to the printer. – KingsInnerSoul Oct 07 '21 at 20:27

1 Answers1

2

The browser does not allow it to print automatically without the user being able to choose the settings to print. This would be extremely problematic as someone can print endless pages without the users permission

David-o
  • 36
  • 3
  • Thank you for the answer , but can i at least make him show the file whit a preview and let him choose if to print it or not but can't make him change the number of pages the user can print ? – Cris Oct 07 '21 at 20:38
  • @Cris The word you're looking for is "with"; I edited your post and changed them all. ["whit" is a word](https://www.bing.com/search?q=define%3A+whit), but it means something completely different. But as the duplicate I posted says in its answers, there is no way of interacting with the printing process other than initiating it. You can suggest things like paper size and orientation, but that's it. – Heretic Monkey Oct 07 '21 at 21:59