🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: be.comp.programming
Article #5379

Problems with printing in Java

#5379
From: Jef Melis
Date: Wed, 09 Apr 2003 09:45
66 lines
3056 bytes
Hi,

I have the following problems :

1. Is there a way to retreive the status of a printer in Windows using Java
??? I want to find out if the printer is out_of_paper, toner_low,
unreachable, ... and those stuff. Anybody an idea ??? (It should only work
under Windows !!)

2. This problem concerns the code snippet. The purpose is to print a
postscript file x times on a Postscript printer. When I set the line
"aset.add(new Copies(nrOfCopies));" in comment, it works and prints the
document 1 time. When I uncomment this line it doesn't find the PrintService
and therefor doesn't do anything.
Does anyone have an explanation for this ??? Or even better, does anyone can
tell me how I have to do this correctly ???

./..
  public void print() throws Exception
  {
    String filename = "test.ps";
    int nrOfCopies = 4;
    String printService = "HP LaserJet 2200-PS";

    // PrintDoc is an implementation of Doc
    Doc pdoc = new PrintDoc(filename);

    // Gets the format of the document
    DocFlavor flavor = pdoc.getDocFlavor();

    // Creates a new attribute set
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();

    /*
     * WARNING : When activating the following rule, there is a problem with
finding the 'Printservice'
     * WE NEED TO CHECK THIS OUT !!!
     */
    //          aset.add(new Copies(nrOfCopies));

    // Locates printer to print the specified document format
    // with the specified attribute set
    PrintService service = null;

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

    for (int i = 0; i < services.length; i++)
    {
      service = services[i];

      if (service.getName().equals(iPrintservice))
        break;
    }

    if (service != null)
    {
      DocPrintJob job = service.createPrintJob();
      job.print(pdoc, aset);
    }
    else
    {
      throw new PrintException("PrintService not found : " + iPrintservice);
    }
  }
../.
Technical Details
Message-ID: <dZRka.38173$t_2.3622@afrodite.telenet-ops.be>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!nntp.abs.net!news-out.cwix.com!newsfeed.cwix.com!ossa.telenet-ops.be!afrodite.telenet-ops.be.POSTED!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fcea4,7c215e422a6dafcd,start
X-Google-Attributes: gidfcea4,public
X-Google-ArrivalTime: 2003-04-09 02:45:48 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!nntp.abs.net!news-out.cwix.com!newsfeed.cwix.com!ossa.telenet-ops.be!afrodite.telenet-ops.be.POSTED!not-for-mail
From: "Jef Melis" <tmp-05@pandora.be>
Newsgroups: be.comp.programming
Subject: Problems with printing in Java
Lines: 69
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
Message-ID: <dZRka.38173$t_2.3622@afrodite.telenet-ops.be>
Date: Wed, 09 Apr 2003 09:45:45 GMT
NNTP-Posting-Host: 213.119.60.105
X-Complaints-To: abuse@telenet.be
X-Trace: afrodite.telenet-ops.be 1049881545 213.119.60.105 (Wed, 09 Apr 2003 11:45:45 MET DST)
NNTP-Posting-Date: Wed, 09 Apr 2003 11:45:45 MET DST
Organization: Telenet Internet