I want to print a text file directly to the default printer installer/set by the OS.
Actually i made raw printing work using the code below it works fine.
But i have some indian local language in the text file which comes as junk.
So i need to print text file via printer driver without user interaction.
I have also tried java.awt.print.PrinterJob class the code is able to print text file but i get a pint dialog.
what i really need is to print text file via printer driver without user interaction. Is there any api or workaround to do so!
Any help/ advice is greatly appreciated !
Thank You in anticipation!
I dont mind. I cant take credit for the code either, i found it and used it with minor modifications.
You might need to figure out what index the printer you want to use has on your system (line 41)
or if theres a way to always get the default-printer.
And what if you have less than 8 print services?
You're close though - PrintServiceLookup has methods getDefaultPrintService() and lookupDefaultPrintService(). The latter is static so you can easily use it. Just be aware that it may return null.
The index '7' in there is what i needed to get MY desired printer at MY network.
('0' for me was windows XPS-Printer, '1' a PDF-Printer, and so on).
So you have to replace it with whatever index-number your printer turns out to be.
That comment i made there was misleading, sorry.
Thanks for the tipps about default printer methos Rob!
I wouldn't count on a number, even if you want one specific printer. What if you add a printer and it gets inserted before index 7? I'd instead get all the PrintService objects and loop through them and get the one you want based on the name.
Joined: Aug 29, 2011
Thanks for the code. And others for their valuable advice.
The code works fine but i am still getting the printer dialog box to print.
Basically i want to use silent printing.
I am still searching for an api to print text file silently to printer.
i am going through my options right now. How about converting my text file to pdf and
use jpedal,iText or something similar API to print silently. Let me know what you people think.
Hmm im running this here on Windows XP and its completely silent, no dialog whatsoever.
I run the program, it terminates, and 2 sec later i hear the printer going off.
Joined: Aug 29, 2011
Sorry! your code works fine in windows.
Actually my default printer was set as pdf printer
i too got it working in windows. However in LINUX it still
pop a dialog. Now working to findout why so?
will post the solution one i get it for linux
meanwhile if anyone gets any thing on silent printing in java kindly reply! Dont close the thread yet!
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: Direct Printing a text file by default printer without user interaction.