Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript - How to tell if window.print() was successful?

I have a page where users will be able to print some pdfs with images and data. I want them to be able to print how many files they want and ,also, to be able to pause them - meaning they can stop the printing and prevent printing of what was NOT already sent to the printer; those who were already sent to the printer cannot be stopped, of course.

The thing is: to be able to pause the printing, I cannot send all the things at once. I have to send them one by one and then sort of receive some return value which will tell me the last print job has finished/was successful, allowing the following file to be printed...

I was using window.print() but I've read there is no return value so perhaps I should let it go.

Any chance I could get a return value to allow the user to control the printing flow?

like image 783
MagisterMundus Avatar asked Dec 30 '25 16:12

MagisterMundus


1 Answers

There really isn't a way to do what you're looking for in a browser. There are the window.onbeforeprint and window.onafterprint events, but there isn't any feedback from the OS printing functionality to the browser.

There's also really no way to handle this in non-browser applications, too. Sure, the OS can tell you if the printer "absorbed" the job, but depending on how the printer is queued that could just mean that the job has moved to a subordinate queue (inside the printer, for example) and that the paper hasn't actually printed.

When I've been asked to do this (label printing in an inventory management application I wrote) I just asked the user to affirm that the print was successful. I didn't like doing it, but there's really no way short of a human looking at the printed output and deciding it's alright to confirm successful printing.

(We just need a printer with a scanner in the paper path that can validate the output... >smile< Then we'd need something after the scanner to validate that a jam in the paper path after the scanner didn't acordian the paper up... Then we'd need a jam sensor jam sensor to make sure the jam sensor didn't jam... It's turtles all the way down.)

like image 53
Evan Anderson Avatar answered Jan 01 '26 07:01

Evan Anderson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!