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.

3
  • Does this answer your question? Print PDF directly from JavaScript Commented Oct 7, 2021 at 20:25
  • 2
    TLDR: It's not possible. That would pose a serious security risk. Commented Oct 7, 2021 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. Commented Oct 7, 2021 at 20:27

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

2 Comments

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 The word you're looking for is "with"; I edited your post and changed them all. "whit" is a word, 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.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.