Results 1 to 5 of 5
  1. #1
    tom_a is offline Member
    Join Date
    Sep 2010
    Posts
    2
    Rep Power
    0

    Default 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:

    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'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.

    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!

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default

    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

  3. #3
    tom_a is offline Member
    Join Date
    Sep 2010
    Posts
    2
    Rep Power
    0

    Default

    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.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,856
    Rep Power
    19

    Default

    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.

  5. #5
    Join Date
    Sep 2012
    Posts
    1
    Rep Power
    0

    Default Re: Force Print API to Use Physical Printer

    hi , everybody. I want to know whether the problem had been resolved :

    HOW TO Force Print API to Use Physical Printer ?

Similar Threads

  1. How to print text file in java(dotmatrix printer)
    By yoganeethi in forum Advanced Java
    Replies: 4
    Last Post: 12-01-2010, 01:45 PM
  2. How to print out data from web page to printer????
    By verma1986 in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 04-03-2010, 05:10 AM
  3. Long wait time before print job reaches printer
    By Astghik in forum AWT / Swing
    Replies: 0
    Last Post: 01-12-2010, 10:29 AM
  4. Can you print direct to printer?
    By tghn2b in forum New To Java
    Replies: 0
    Last Post: 02-26-2009, 08:58 AM
  5. jsp program for client side printer to print these 2 strings on 3/3
    By for453 in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 08-07-2007, 04:42 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •