🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: be.comp.programming
2 messages
2 total messages Started by Jef Melis Wed, 09 Apr 2003 09:45
Problems with printing in Java
#5379
Author: 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);
    }
  }
../.
Re: Problems with printing in Java
#5395
Author: Jef Melis
Date: Sun, 13 Apr 2003 19:10
84 lines
3510 bytes
Is there no one that could help me with these problems ??? It is very
important for me !!

Kind regard,

Jef

"Jef Melis" <tmp-05@pandora.be> wrote in message
news:dZRka.38173$t_2.3622@afrodite.telenet-ops.be...
> 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);
>     }
>   }
> ../.
>
>
>
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads