On Tuesday 11 September 2007, Tobias Krais wrote:
> Hi Andreas,
>
> >> So I can set a print option of "Wait" to "true" and my program
> >> will wait until the document is printed?  Do I understand that
> >> properly? That would simplify several questions I've had along the
> >> way.
> >
> > It makes your XPrintable.print() call synchron !
> > If your call returns the document was printed (at least the content
> > was transfered completely to the underlying print queue of your
> > system). That means you can close the document afterwards without
> > any problems and you can shutdown the whole office without any
> > problems.
>
> pretty cool your tip! Hal, I implemented it and tested it and I can
> share the easy code with you:
> -----%<-----
> // Querying for the interface XPrintable on the loaded document
> XPrintable xPrintable = (XPrintable)
>         UnoRuntime.queryInterface(XPrintable.class, this.xComponent);
>
> // Making the print job syncronous. Thus the program continues after
> // printing is finished. A print job listener is not needed.
> PropertyValue[] printOpts = new PropertyValue[1];
> printOpts[1] = new PropertyValue();
> printOpts[1].Name = "Wait";
> printOpts[1].Value = new Boolean(true);
>
> try {
>       xPrintable.print(printOpts);
> } catch (IllegalArgumentException e) {
>       e.printStackTrace();
> }
> -----%<-----

Okay, I changed it from what I read here (specifying a boolean instead 
of a string) to get this:


        PropertyValue[] printOpts = new PropertyValue[2];
        printOpts[0] = new PropertyValue();
        printOpts[0].Name = "Name";
        printOpts[0].Value = sPrinter;
        printOpts[1] = new PropertyValue();
        printOpts[1].Name = "Wait";
        printOpts[1].Value = new Boolean(true);

I left the print listener in just in case there was a problem and that 
caused a problem.  I removed the print listener and it worked fine.  
Much simpler code and I figure I might save a small amount of time on 
each document since I can go on as soon as it finishes, instead of 
possibly losing a bit of time sleeping in a loop.  While that isn't 
much time per document, in some cases my clients are printing hundreds 
of documents and the time could add up.  Not by much, but it might make 
the pages print faster.

Hal

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to