Results 1 to 5 of 5
- 09-10-2010, 05:14 PM #1
Member
- Join Date
- Sep 2010
- Posts
- 2
- Rep Power
- 0
Force Print API to Use Physical Printer
Greetings,
I'm using the print API (javax.print) to print documents that should not be redistributed electronically. Therefore I've set up a method to print to the default print service without showing the user the print dialog.
My problem is that I need to ensure that the default print service is using a physical printer and not some sort of document writer. Does anybody know if this is possible?
Details:
My code is basically this:
I'm testing on Windows using a couple physical printers as wells as the CutePDF writer. When I examine the attributes and implementation classes of the PrintService and PrintJob, I can't see any differences between the physical printers and the PDF Writer.Java Code:PrintService ps = PrintServiceLookup.lookupDefaultPrintService(); DocPrintJob job = ps.createPrintJob(); // do some stuff to get a reference to a Connection (conn) that is streaming my document SimpleDoc doc = new SimpleDoc(conn.getInputStream(), DocFlavor.INPUT_STREAM.AUTOSENSE, null); job.addPrintJobListener(new MyCustomPrintJobListener()); job.print(doc, new HashPrintRequestAttributeSet()); conn.getInputStream().close();
I believe that this is possible somehow -- smartsource.com seems to have accomplished it. If you go to smartsource.com and print a coupon, you'll see that they're using an Applet to send their coupons directly to the default printer (similar to what I want to do with my documents). However, if you change your default printer to the PDF writer, they tell you that it isn't supported.
Any ideas? Any help is appreciated!
- 09-11-2010, 03:52 AM #2
Disclaimer: I don't have any first-hand knowledge of this. The advice is on the basis of reading the API.
Take a look at the classes StreamPrintServiceFactory, StreamPrintService and DocFlavor. Particularly StreamPrintService#getOutputFormat()
db
- 09-13-2010, 03:00 PM #3
Member
- Join Date
- Sep 2010
- Posts
- 2
- Rep Power
- 0
Thanks for the reply. I've looked at those classes and I don't think they help my situation.
The different DocFlavor types are used to identify what type of data is being printed, but not the tangible output from the printer.
Also, I don't think StreamPrintService (and StreamPrintServiceFactory) interact with the printers. Rather, they seem to classes that allow an application to "print" to an output stream that is maintained by the application. The StreamPrintServiceFactory instances available on my system seem to be unrelated to the printers installed.
- 09-13-2010, 03:24 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Your code will be reliant on the info it can get from the printer managing stuff on the OS you're on, so any check you do could be (I presume) faked...however, is there something you could do with the PrintServiceAttributes? Even if it's just Make and Model, filtering out known PDF writers.
- 09-03-2012, 05:40 AM #5
Member
- Join Date
- Sep 2012
- Posts
- 1
- Rep Power
- 0
Similar Threads
-
How to print text file in java(dotmatrix printer)
By yoganeethi in forum Advanced JavaReplies: 4Last Post: 12-01-2010, 01:45 PM -
How to print out data from web page to printer????
By verma1986 in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 04-03-2010, 05:10 AM -
Long wait time before print job reaches printer
By Astghik in forum AWT / SwingReplies: 0Last Post: 01-12-2010, 10:29 AM -
Can you print direct to printer?
By tghn2b in forum New To JavaReplies: 0Last Post: 02-26-2009, 08:58 AM -
jsp program for client side printer to print these 2 strings on 3/3
By for453 in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 08-07-2007, 04:42 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks