Page 1 of 1

Open and print a document while it's hidden in the UI. C#

Posted: Wed Oct 22, 2014 4:35 am
by terina
Is it possible to open an OO writer document, fill textboxes, print the document and close it without showing the whole process in the user interface?

I've hidden the document with the property value "hidden" (see below) but it doesn't seem to be enough. The document will pop up and close itself in the user interface just before the document gets printed. How can I make it hidden under the whole process?

Code: Select all

string url = Path.GetFullPath(@"myDocument.odt");
           var uri = new System.Uri(url);
           converted = uri.AbsoluteUri;

           XComponentContext oStrap = uno.util.Bootstrap.bootstrap();
           XMultiServiceFactory oServMan = (XMultiServiceFactory)oStrap.getServiceManager();
           oDesk = (XComponentLoader)oServMan.createInstance("com.sun.star.frame.Desktop");

PropertyValue[] propVals = new PropertyValue[1];
propVals[0].Name = "Hidden";

 oDoc = oDesk.loadComponentFromURL(converted, "_blank", 0, propVals);

           unoidl.com.sun.star.container.XEnumerationAccess xtextfields =
          ((unoidl.com.sun.star.text.XTextFieldsSupplier)oDoc).getTextFields();
           unoidl.com.sun.star.container.XEnumeration enumaration = xtextfields.createEnumeration();

while (enumaration.hasMoreElements())
                {
                    uno.Any field = enumaration.nextElement();
                   
                    if (field.Value is unoidl.com.sun.star.text.XTextField)
                    {
                        string name = ((unoidl.com.sun.star.text.XTextField)field.Value).getAnchor().getString();
                       

                        if (name == "CustomerName")
                        {
                            ((unoidl.com.sun.star.text.XTextField)field.Value).getAnchor().setString(lblCustomerName.Text);

                        }

                   }
              }


[...]

//PRINT SECTION

PropertyValue[] propValues = new PropertyValue[2];
propValues[0] = new PropertyValue { Name = "Wait", Value = new uno.Any(true) };
propValues[1] = new PropertyValue { Name = "CopyCount", Value = new uno.Any(Convert.ToInt16(intNumberOfCopies)) };
((XPrintable)oDoc).print(propValues);
oDoc.dispose();
oDoc = null;

If i don't get the code above to work fine, another possibility could be to open a copy of the OO writer document through C#. The user could then manually print the document. Is this possible to implement?

Re: Open and print a document while it's hidden in the UI. C

Posted: Wed Oct 22, 2014 8:16 am
by B Marcelly
Set the propVals[0].Value at True.