The Artima Developer Community
Sponsored Link

Java Answers Forum
JPS: Printer Discovery w/ Port settings

1 reply on 1 page. Most recent reply: Oct 15, 2002 4:38 AM by Carsten F. Hansen

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
conick

Posts: 2
Nickname: conick
Registered: Sep, 2002

JPS: Printer Discovery w/ Port settings Posted: Sep 27, 2002 9:28 AM
Reply to this message Reply
Advertisement
I thought JPS was just the API I was looking for. I could finally discover printers available to a workstation.

However, I would also like to be able to retrieve the ports these printers are using. Any ideas? Is there something I missed in the docs? Any third party solutions out there that I haven't found?

For example:
A Windows local printer may be "LPT1"
A Windows network printer "\\server\printername"
Linux local "/dev/lp0"

Ive looked through the attributes and a couple looked promising (Destination, PrinterLocation) but "out.prn" and null were returned, respectively.

Any comments welcome. Even "It Can't be Done, you Moron"


Carsten F. Hansen

Posts: 3
Nickname: cfh
Registered: Oct, 2002

Re: JPS: Printer Discovery w/ Port settings Posted: Oct 15, 2002 4:38 AM
Reply to this message Reply
I don't know if you have solved your problem, but here
are some ways of doing it.


import javax.print.*;
import java.awt.print.*;

public class FindPrinter
{ public static void main(String[] args)
{

PrintService ps = PrintServiceLookup.lookupDefaultPrintService();
String ss = ps.getName();
System.out.println( "Default printer : " + ss );

PrintService[] pservices = PrinterJob.lookupPrintServices();
System.out.println( "Installed printers:");
for (int i = 0; i < pservices.length; i++)
{
System.out.println( "\t\tPrinter " + i + " \"" + pservices[ i ] + "\"");
}

System.out.println( "Printer: \"" + ps.getName() + "\"");

System.out.println( "Printer: \"" + pservices[ 0 ].getName() + "\"");

} // End main
} // End class


I don't know about ports yet, but that must be possible too.

Flat View: This topic has 1 reply on 1 page
Topic: Look&Feel Previous Topic   Next Topic Topic: need help please

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use