Ich habe ein kleines Programm, dass ein übergebenes Dokument auf einen übergebenen Drucker ausgibt.
Das einzigste Problem ist, dass ich nicht weiss, wie ich die Anzahl der Ausdrucke zu verwenden habe.
Hier das Programm listinmg (Auszugsweise)
Code: Alles auswählen
XComponentContext xContext = Bootstrap.bootstrap();
if (xContext == null) {
System.err.println("ERROR: Could not bootstrap default Office.");
}
else {
System.out.println("Connected to a running office ...");
}
// get the remote office service manager
com.sun.star.lang.XMultiComponentFactory xMCF = xContext.getServiceManager();
Object oDesktop = xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", xContext);
com.sun.star.frame.XComponentLoader xCompLoader =
(com.sun.star.frame.XComponentLoader) UnoRuntime.queryInterface(com.sun.star.frame.XComponentLoader.class, oDesktop);
java.io.File sourceFile = new java.io.File(sDokument);
StringBuffer sUrl = new StringBuffer("file:///");
sUrl.append(sourceFile.getCanonicalPath().replace('\\', '/'));
com.sun.star.beans.PropertyValue BeanProp[] = new com.sun.star.beans.PropertyValue[1];
// Load a Writer document, which will be automaticly displayed
BeanProp[0] = new com.sun.star.beans.PropertyValue();
BeanProp[0].Name = "Hidden";
BeanProp[0].Value = true;
com.sun.star.lang.XComponent xComp = xCompLoader.loadComponentFromURL(sUrl.toString(), "_blank", 0, BeanProp);
// Querying for the interface XPrintable on the loaded document
com.sun.star.view.XPrintable xPrintable =
(com.sun.star.view.XPrintable) UnoRuntime.queryInterface(com.sun.star.view.XPrintable.class, xComp);
// Setting the property "Name" for the favoured printer (name of IP address)
com.sun.star.beans.PropertyValue propertyValue[] = new com.sun.star.beans.PropertyValue[1];
propertyValue[0] = new com.sun.star.beans.PropertyValue();
propertyValue[0].Name = "Name";
propertyValue[0].Value = sPrinter;
// Setting the name of the printer
xPrintable.setPrinter(propertyValue);
// Setting the property "Pages" so that only the desired pages will be printed.
propertyValue[0] = new com.sun.star.beans.PropertyValue();
if (args.length == 6) {
propertyValue[0].Name = "Pages";
propertyValue[0].Value = args[5];
}
else {
System.out.println("Printing all Pages ...");
}
// Setting the property "CopyCount" for the number of Copies
//propertyValue[0] = new com.sun.star.beans.PropertyValue();
//propertyValue[0].Name = "CopyCount";
//propertyValue[0].Value = args[1];
// Here Insert the Printlistener:
XPrintJobBroadcaster xPrintStat = (XPrintJobBroadcaster) UnoRuntime.queryInterface(XPrintJobBroadcaster.class, xPrintable);
PrintListener oListener = new PrintListener();
xPrintStat.addPrintJobListener(oListener);
// Printing the loaded document
xPrintable.print(propertyValue);
while ( oListener.isStillPrinting() ) {
Thread.sleep(1000);
}
xPrintStat.removePrintJobListener(oListener);
// Closing the printed Document
com.sun.star.frame.XStorable xStorable =
(com.sun.star.frame.XStorable)UnoRuntime.queryInterface(com.sun.star.frame.XStorable.class, xComp );
com.sun.star.util.XCloseable xCloseable =
(com.sun.star.util.XCloseable)UnoRuntime.queryInterface(com.sun.star.util.XCloseable.class, xStorable);
if ( xCloseable != null ) {
xCloseable.close(true);
}
else {
xComp.dispose();
}
//Hier entlade ich soffice.bin aus dem Speicher...
XDesktop xDesk = (XDesktop)UnoRuntime.queryInterface(XDesktop.class, oDesktop);
xDesk.terminate();
CLibrary.INSTANCE.SendMessageA( iHandle, iMessage, 0, 0 );
System.exit(0);
Könnte mir da bitte einer weiterhelfen?