Hi Brett, * On Fri, Oct 28, 2011 at 12:42:18PM +0200, Bert Frees wrote: > Hello Jürgen and Ariel, > > Thanks for your help. I appreciate you want to solve this MacOS issue when > there is more time. > > Ariel, the suggested code works :) I am now trying to find a way to send a > byte stream to a printer.
let me see if I get it: you are trying to print arbitrary stuff just like in this java snippet http://download.oracle.com/javase/6/docs/api/javax/print/PrintService.html > Could XPrinterPropertySet.setBinarySetup be used > for this purpose maybe? this method is for setting the Printer setup (that is, the printer configuration), not for setting the data to be printed > The com.sun.star.awt.XPrinter service only seems to > support graphical data, am I right? mmm I've only used this to get the printer name, and then print an OOo document, via the css.view.XPrintable interface implemented by OOo documents. Printing in OOo is well supported for printing *office* documents (not any data you may want to print, let's say a PDF file, for example. If you want to print an arbitrary file, let's say a PNG picture, you have to import it as an OOo Draw document and print that office document; AFAIK there is now away to then the PNG image directly to the printer - and this is not wrong, OOo is an office suite, not a printing application). On the other hand, looking at the code in http://svn.apache.org/viewvc/incubator/ooo/trunk/main/toolkit/workben/controls.cxx?view=markup#l125 you are able to draw onto a virtual device and print it. See the attached code, it is Java version of this C++ sample. Unfortunately this does not work, there is a bug in the implementation: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/toolkit/source/awt/vclxprinter.cxx?view=markup#l325 if ( mpListener.get() ) always evaluates to false, that shared pointer has never been set before. For what I could understand there, it should be: if ( mpPrinter.get() ) { maInitJobSetup = mpPrinter->GetJobSetup(); mpListener.reset( new vcl::OldStylePrintAdaptor( mpPrinter ) ); } this seems to "work"... well, the "Print" dialog shows up now, with the text drawn onto the virtual device: http://arielch.fedorapeople.org/images/vclxprinter.png funny indeed. In short, print office documents, using the well known interfaces described in the view module http://api.openoffice.org/docs/common/ref/com/sun/star/view/module-ix.html http://api.openoffice.org/docs/common/ref/com/sun/star/view/XPrintable.html http://api.openoffice.org/docs/common/ref/com/sun/star/view/XPrintable-xref.html http://ooo-wiki.apache.org/wiki/Documentation/DevGuide/OfficeDev/Storing_Documents#Printing_Documents Regards -- Ariel Constenla-Haile La Plata, Argentina
/*
* PrintDemo.java
*
* Created on 2011.10.28 - 11:36:35
*
*/
package org.openoffice.sdk.awt;
import com.sun.star.awt.XDevice;
import com.sun.star.awt.XGraphics;
import com.sun.star.awt.XPrinter;
import com.sun.star.awt.XPrinterServer;
import com.sun.star.uno.XComponentContext;
import com.sun.star.comp.helper.Bootstrap;
import com.sun.star.uno.UnoRuntime;
/**
*
* @author ariel
*/
public class PrintDemo {
/** Creates a new instance of PrintDemo */
public PrintDemo() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try {
// get the remote office component context
XComponentContext xContext = Bootstrap.bootstrap();
if (xContext == null) {
System.err.println("ERROR: Could not bootstrap default
Office.");
} else {
String aPrinter = null;
XPrinterServer xPrinterServer = (XPrinterServer)
UnoRuntime.queryInterface(
XPrinterServer.class,
xContext.getServiceManager().createInstanceWithContext(
"com.sun.star.awt.PrinterServer", xContext));
if (xPrinterServer != null ){
String[] sPrinters = xPrinterServer.getPrinterNames();
aPrinter = ( sPrinters.length > 0 ) ? sPrinters[0] : null;
}
if (aPrinter != null){
System.out.printf("PRINTER: %s\n", aPrinter);
XPrinter xPrinter = xPrinterServer.createPrinter(aPrinter);
xPrinter.start("AOOo AWT API Printing Demo", (short)1,
true);
XDevice xDevice = xPrinter.startPage();
XGraphics xGraphics = xDevice.createGraphics();
xGraphics.drawText(10, 10, "This is a demo");
xPrinter.endPage();
xPrinter.end();
}
}
}
catch (java.lang.Exception e){
e.printStackTrace();
}
finally {
System.exit( 0 );
}
}
}
diff --git a/toolkit/source/awt/vclxprinter.cxx
b/toolkit/source/awt/vclxprinter.cxx
index 619ba44..b0a2037 100644
--- a/toolkit/source/awt/vclxprinter.cxx
+++ b/toolkit/source/awt/vclxprinter.cxx
@@ -327,7 +327,7 @@ sal_Bool VCLXPrinter::start( const ::rtl::OUString&
/*rJobName*/, sal_Int16 /*nC
::osl::Guard< ::osl::Mutex > aGuard( Mutex );
sal_Bool bDone = sal_True;
- if ( mpListener.get() )
+ if ( mpPrinter.get() )
{
maInitJobSetup = mpPrinter->GetJobSetup();
mpListener.reset( new vcl::OldStylePrintAdaptor( mpPrinter ) );
pgpIifN6hCRIy.pgp
Description: PGP signature
