Seite 1 von 1

Wie steuert man die Anzahl der Ausdrucke? *GELÖST*

Verfasst: Mi, 07.10.2009 10:27
von ipconfig
Servus miteinander.

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);
Ich bin ziemlich sicher, dass mit dem Property "CopyCount" etwas gemacht werden muss, aber leider sind meine Java und OO Kentnisse dafür zu bescheiden.

Könnte mir da bitte einer weiterhelfen?

Re: Wie steuert man die Anzahl der Ausdrucke?

Verfasst: Mi, 07.10.2009 11:53
von ipconfig
Hmm...

Ich habe soweit meine Code erweitern können:

Code: Alles auswählen

import com.sun.star.beans.*;
...
            PropertyValue propertyValue[] = new PropertyValue[3];

            // Setting the property "CopyCount" for the number of Copies
            propertyValue[0] = new com.sun.star.beans.PropertyValue();
            propertyValue[0].Name = "CopyCount";
            propertyValue[0].Value = new Short( (short)iAnzahl );

            xPrintable.print(propertyValue);
Jetzt habe ich aber folgendes PProblem:
übergebe ich als Anzahl eine 1 wird es 1mal ausgedruckt
übergebe ich eine 2 wird es 4 mal ausgedruckt...
übergebe ich eine 3 wird es 9 mal ausgedruckt...

Weiss jemand rat?

Re: Wie steuert man die Anzahl der Ausdrucke? *GELÖST*

Verfasst: Mi, 07.10.2009 12:16
von ipconfig
Aha:

Es gibt ein Property namens "Collate", wenn man das auf true setzt geht es...