2

Is it possible to cancel a print job once it has already been put into the document queue in windows with java code?

user469650
  • 51
  • 2
  • 4

1 Answers1

0

It looks like this is what you're looking for (note that I haven't tested the example myself)

http://docs.oracle.com/javase/7/docs/api/javax/print/CancelablePrintJob.html

tresf
  • 7,103
  • 6
  • 40
  • 101
  • Thanks for finding this. This does seem to work to stop a print job that shows spooling in the document queue but is there a way to cancel the job once it is fully in the print queue? If I press the cancel button in that example code you posted I get: javax.print.PrintException: Job could not be cancelled. – user469650 Oct 08 '10 at 13:40
  • I guess what I might be looking at is a way to control the windows print spooler rather than the print job as the print job is already finished. Or is there a way to set an auto timeout to detele the document from the print queue with a windows setting or with java code? – user469650 Oct 08 '10 at 15:30
  • I'm not sure if there is an easy way to stop a specific job. It will probably involve using JNI, but I haven't coded enough windows specific stuff to tell you exactly how. However, if all you need is to *clear* the print queue, then you can possibly execute this using Runtime.getRuntime().exec() net stop spooler del C:\WINDOWS\system32\spool\PRINTERS\*.* /q net start spooler –  Oct 11 '10 at 07:41
  • Voting down due to link rot, the site provided has been moved. Editing original post. – tresf Sep 18 '15 at 17:27
  • This thread may also be of interest. It talks about using JNA to clear a print queue: https://github.com/java-native-access/jna/issues/661#issuecomment-221025927 – tresf Jan 25 '18 at 15:56