-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hal Vaughan wrote:
> On Tuesday 11 September 2007, Andreas Schlüns wrote:
>> Hello Tobias & Hal
>>
>>>>> I think I've been told, and likely here, that in 2.0.x,
>>>>> print listeners like this are no longer necessary, but I'm
>>>>> having a bit of a problem searching and finding this
>>>>> comment and what the background is.
>>>>>
>>>>> In 2.0.x, can I print, then close the document without
>>>>> listening for when the print job is done?  Can someone
>>>>> confirm this for me? I've been stuck on this problem for
>>>>> about a month (I thought it was other possibilities, and
>>>>> had another couple issues as well) and I'm at a point where
>>>>> I need to solve it and my client is, understandably,
>>>>> anxious about it.
>>>> Tried it without the print listener and it crashed.  Guess it
>>>>  still needs listeners.
>>> I wrote a little Java program being able to do the same you
>>> want to do. It opens a document, prints it and closes it.
>>> Calling the program again prints the next document,...
>>>
>>> I also ran into troubles without the print listener. Closing
>>> the document too fast will crash the print job. A print job
>>> listener is good for other reasons, too.
>>>
>>> I can send you my code if needed. Its an easy thing. But well,
>>> its late in Europe and you wont get much help around this
>>> time...
>> You do not need realy a print listener to know when printing of
>> the document will be finished and you can close the document.
>
> In my case, I print, then close, and that seems to be too fast.  I
> tried without a print listener and it didn't work.
>
>> The real problem you have ... printing is by default an
>> asynchronous operation. And of course - if you try to dispose a
>> document which is currently in printing state it can crash (at
>> least it shouldnt ... but it can).
>>
>> The best solution: start the printing job with a well documented
>> parameter "Wait=true". see css.view.PrintOptions for further
>> details.
>
> 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.
>
>> On the other side it can be important how do you close the
>> document. Do you use dispose() or close(). Documentation say you
>> have to preferr XClosable.close().
>
> That's what I'm using.
>
>> Further its always a good idea to control the lifetime of a
>> document without any exception and call close(false). Means -
>> please do not deliver the ownership to the document itself. It
>> can work for a while ... but if you close the application it can
>> make trouble. Because all documents not finished within her jobs
>> ... but closed with "false" does not know how they should handle
>> these situation right. They can of course handle it right ... but
>> mostly they dont do it :-)
>
> But if I use "Wait=true" for printing, then close immediately after
> the doc has been printed, and only load in one at a time, then that
> should eliminate any problems, right?
>
> Hal
>
> ---------------------------------------------------------------------
>  To unsubscribe, e-mail: [EMAIL PROTECTED] For
> additional commands, e-mail: [EMAIL PROTECTED]
>
Hi Hal,
this code is for you (I hope):

public class PrintDocument {

................................

private static int flag;

public void fire() {
.........................

                    XPrintable xPrintable =
                (XPrintable) UnoRuntime.queryInterface(XPrintable.class,
                    this.xComponent);

                    XPrintJobBroadcaster xPrintJobBroadcaster =
                        (XPrintJobBroadcaster) UnoRuntime.queryInterface(
                            XPrintJobBroadcaster.class, this.xComponent);

                    XPrintJobListener xPrintJobListener = new
Printeable();
                
xPrintJobBroadcaster.addPrintJobListener(xPrintJobListener);

                    xPrintable.print(this.getPrintOptions());

                    while (PrintDocument.flag ==
PrintableState.JOB_STARTED_value
                        || PrintDocument.flag ==
PrintableState.JOB_SPOOLED_value) {
                        try {
                            Thread.sleep(100);
                        }
                        catch (InterruptedException e) {
                               System.err.println(e.getStackTrace());
                        }
                    }
.........................................
}

private class Printeable implements XPrintJobListener {

        public void printJobEvent(PrintJobEvent arg0) {

            int state = arg0.State.getValue();

            switch (state) {
                case PrintableState.JOB_STARTED_value:
                    PrintDocument.flag = PrintableState.JOB_STARTED_value;
                    break;

                case PrintableState.JOB_SPOOLED_value:
                    PrintDocument.flag = PrintableState.JOB_SPOOLED_value;
                    break;

                case PrintableState.JOB_COMPLETED_value:
                    PrintDocument.flag =
PrintableState.JOB_COMPLETED_value;
                    break;

                case PrintableState.JOB_ABORTED_value:
                    PrintDocument.flag = PrintableState.JOB_ABORTED_value;
                    break;

                case PrintableState.JOB_FAILED_value:
                    PrintDocument.flag = PrintableState.JOB_FAILED_value;
                    break;

                case PrintableState.JOB_SPOOLING_FAILED_value:
                    PrintDocument.flag =
                        PrintableState.JOB_SPOOLING_FAILED_value;
                    break;
            }

        }

        public void disposing(EventObject arg0) {

            PrintDocument.flag = PrintableState.JOB_COMPLETED_value;
        }

    }

}


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)
Comment: Using GnuPG with Mandriva - http://enigmail.mozdev.org

iD8DBQFG5kVl0o6rRgJgVfERAqmiAJ0dHqV3JKurntAjSQDBHfQmYQOCSACg03PH
RVCuQMbZ6ZApH0bodVkLmqI=
=MWod
-----END PGP SIGNATURE-----

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

Reply via email to