Thank you Mikhail, The reason I am trying to do it this way is that we need to print or convert thousands of documents each month and when I create a Model Frame and Controller, OpenOffice inevitablly hangs after a short while, probably something to do with threading in OpenOffice and maybe finalizers in java. So I am trying to keep the number of objects and interactions to an absolute minimum to see if that helps. As a result, except for printing, the behaviour of OpenOffice does seems much more stable. So could you point me in the right direction as to how to create the frame or the view an attach it to the model without a Controller (if that's possible) in a way that would enable printing.
Daniel > -----Original Message----- > From: Mikhail Voitenko [mailto:[email protected]] > Sent: February 18, 2009 2:27 AM > To: [email protected] > Subject: Re: [api-dev] Xprintable getPrinter returns a zero > length sequence > > Hi Daniel, > > Currently the model needs view to be able to print. > > To prevent showing of the document after loading please try > to load it using "loadComponentFromURL" method and provide > "Hidden" parameter in MediaDescriptor. > > That should create an invisible frame for the document, and > the printing should be possible in this case. > > Best regards, > Mikhail. > > On 02/18/09 03:17, Daniel Brosseau wrote: > > Hi, > > > > I am afraid I am stumped and need some help with this. I have a > > component, a com.sun.star.text.TextDocument that has only > an Xmodel, > > no Frame or Controller, that I have populated throupgh a > > Xloadable.load. The component has loaded succesfully and I > can get its > > properties through XPropertySet and XPropertySetInfo. It > has content, > > word count, character count, etc > 0 and I can extract text through > > XTextCursor.getString(). I can extract the Xmodel's URL > without a problem. > > > > So far so good. The problem is when I come to print. I get the > > XPrintable interface > > > > XPrintable xPrintable = (XPrintable) > UnoRuntime.queryInterface( > > XPrintable.class, xComponent ); > > if ( xPrintable == null ) > > return; > > > > XPrintJobBroadcaster xPrintJobBroadcaster = > > (XPrintJobBroadcaster) UnoRuntime.queryInterface( > XPrintJobBroadcaster.class, xPrintable ); > > LocalPrintJobListener xPrintJobListener = new > > LocalPrintJobListener(); > > xPrintJobBroadcaster.addPrintJobListener( > xPrintJobListener ); > > > > PropertyValue[] printerDesc = new PropertyValue[1]; > > printerDesc[0] = new PropertyValue(); > > printerDesc[0].Name = "Name"; > > printerDesc[0].Value = printerName; > > xPrintable.setPrinter( printerDesc ); > > > > printerDesc = xPrintable.getPrinter(); > > for( int i = 0; i < printerDesc.length; i++ ) > > { > > m_lbaLogger.info( "printerDesc[" + i + "] Name " + > > printerDesc[i].Name + ", value " + > printerDesc[i].Value.toString() ); > > } > > > > dsUrl = dsUrl.replace( '\\', '/' ); > > PropertyValue[] printOpts = new PropertyValue[4]; > > printOpts[0] = new PropertyValue(); > > printOpts[0].Name = "FileName"; > > printOpts[0].Value = dsUrl; > > printOpts[1] = new PropertyValue(); > > printOpts[1].Name = "CopyCount"; > > printOpts[1].Value = new Short( (short)1 ); > > printOpts[2] = new PropertyValue(); > > printOpts[2].Name = "Pages"; > > printOpts[2].Value = "1-999999"; > > printOpts[3] = new PropertyValue(); > > printOpts[3].Name = "Wait"; > > printOpts[3].Value = new Boolean( true ); > > > > xPrintable.print( printOpts ); > > > > int nWait = 0; > > int nMaxWait = 10000; > > m_lbaLogger.info( "Printing to file " + dsUrl + " > through printer " > > + printerName ); > > while ( xPrintJobListener.getState() == null || > > xPrintJobListener.getState() == PrintableState.JOB_STARTED ) > > { > > Thread.sleep( 100 ); > > nWait += 100; > > if ( nWait > nMaxWait ) > > { > > m_lbaLogger.warning( "Could not print document" ); > > break; > > } > > } > > m_lbaLogger.info( "Waited " + nWait + "ms to print > document, > > ending print state was " + xPrintJobListener.toString() ); > > > > xPrintJobBroadcaster.removePrintJobListener( > xPrintJobListener > > ); > > > > After xPrintable.setPrinter( printerDesc ), I getPrinter() > to see if > > anything has been set but the printerDesc array has a length of 0. > > Then when I try to print, the PrintJobListner always times > out and the > > Printer's xPrintJobListener.getState() == null which means > the print > > job did not even start. The printer name is a valid printer as > > confirmed by > > > > private boolean isPrinter( String printerName ) > > { > > // Look up all services > > javax.print.PrintService[] services = > > javax.print.PrintServiceLookup.lookupPrintServices( null, null ); > > for ( int i = 0; i < services.length; i++ ) > > { > > if ( services[i].getName().trim().equalsIgnoreCase( > > printerName.trim() ) ) > > { > > return true; > > } > > } > > return false; > > } // isPrinter > > > > Is there anything evident that I am missing here? Is there > any reason > > that an Xmodel without a Controller or Frame should not print? > > > > Any help would be greatly appreciated. > > > > Daniel > > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [email protected] > > For additional commands, e-mail: [email protected] > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
