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

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
terina
Posts: 2
Joined: Mon Jun 02, 2014 2:52 pm

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

Post 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?
OpenOffice 4.0.1 on Windows 7
B Marcelly
Volunteer
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

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

Post by B Marcelly »

Set the propVals[0].Value at True.
Bernard

OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
Post Reply