Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2006

Tip: Looking for answers? Try searching our database.

Dynamic Network Printer Discovery and Administration via jcifs.samba.org.

Thread view: 
Rob@Bedford - 21 Apr 2006 14:28 GMT
I am working on a large-scale reporting solution. One component is to
be able to scan the network for all printers and maintain a record of
these printers. I have read many, many posts on these forums with
similar questions, most of which do not have any answers. Below is the
progress I have made so far, hopefully someone can offer some
input/insight.

1. Finding Network Printers - I used jcifs to browse the network and
find all shared devices that were printers.

Code:

private static void findAllPrinters() throws Exception {
       SmbFile root = new SmbFile("smb://domain;USR:PASS@domain");
       Hashtable printerHash = new Hashtable();

       searchForPrinters(root, printerHash);

       Enumeration keys  = printerHash.keys();
       System.out.println("Number of Printers Found: " +
printerHash.size());
       SmbFile file = null;
       while (keys.hasMoreElements()) {
           file = ((SmbFile)keys.nextElement());
           System.out.println("UNC: " + file.getUncPath());
         }
   }

   private static void searchForPrinters(SmbFile root, Hashtable
printers) throws Exception {
       SmbFile[] kids=  null;

       try {
           kids = root.listFiles();
       } catch (Exception e) {

       }
       if (kids == null)
           return;

       for (int i = 0; i < kids.length; i++) {
           if (kids[i].getType() == SmbFile.TYPE_WORKGROUP ||
kids[i].getType() == SmbFile.TYPE_SERVER)
               searchForPrinters(kids[i], printers);
           else if (kids[i].getType() == SmbFile.TYPE_PRINTER) {
               printers.put(kids[i], Boolean.TRUE);
           }
       }
   }

By doing this I can find each printer on my network that I can find
when I use windows control panel and search for network printers.

2. I can print a test to any printer successfully.
Code:

       FileOutputStream fos = new
            FileOutputStream("\\\\PrintShare\\MyPrinter"); //hardcoded for test,
but taken from output of part #1 above.
       PrintStream ps = new PrintStream(fos);
       ps.print("\r");
       ps.print("This page will be printed directly to the printer.");
       ps.print("\f");
       ps.close();

3. This is where i need help. Continuing on what I have already
accomplished...
A. How can I create a more complex printer reference to allow me to
control number of copies, color vs. bw, page layout, page size, obtain
details from printer such as acceptable page sizes, data types
printable, etc.
B Be able to detect printer errors and if the page has completed.

And and all input and/or collaboration is apprecaited! I feel I am
close to finding the link, but not sure where to find the missing
puzzle piece.

Thx,
Rob
Thomas Weidenfeller - 21 Apr 2006 14:53 GMT
> 3. This is where i need help. Continuing on what I have already
> accomplished...

You have apparently chosen to go for a Windows-only solution. So I don't
see the point to do this in Java. Using native windows services and APIs
might be a better choice. The cross-platform Java printing APIs (there
are several) are something between just horrible and madly broken.

If you want to do it in cross-platform Java,
http://java.sun.com/j2se/1.5.0/docs/guide/jps/spec/JPSTOC.fm.html and
hope that your VM comes with a print service provider which can discover
all your printers on your Windows network (or try to find a third party
print service provider implementation which works for you).

/Thomas
Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/

Rob@Bedford - 24 Apr 2006 20:18 GMT
The network that this solution is being designed for is a windows
network, and it will be interracting with various other java programs
(hence my design choices thus-far).  I have reviewed that website and
it repeats what a lot of the various sites say...

PrintService[] service = PrintServiceLookup.lookupPrintServices(flavor,
aset);

However this only works if the printers (network or local printers) are
installed on the system.  My goal is to dynamicially sniff out the
printers on the network (in my office there are approx. 45).  In
"theory" I will do this and query the printers for their various data
flavors (PDF, PS, GIF) etc. and be able to tell the users which ones
offer which and even recommend a printer.
Rob@Bedford - 26 Apr 2006 18:26 GMT
Am currently researching JNDI and LDAP to see if this is a possible
avenue.  Will continue to update my progress in case others are doing
something similar.  As always, if you have input based on above feel
free to post. :)

Thx.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.