Check out this solution . There might need some changes on the declaration of the PropertyValues
public void Conversion(string sourcefile, string exportfile)
{
Type tServiceManager = Type.GetTypeFromProgID("com.sun.star.ServiceManager", true);
object oServiceManager = System.Activator.CreateInstance(tServiceManager);
object oDesktop = Invoke(oServiceManager,"createinstance",BindingFlags.InvokeMethod,"com.sun.star.frame.Desktop");
//Load Document
Object[] arg = new Object[4];
arg[0] = PathConverter(sourcefile); // or "private:factory/swriter" for a blank Document
arg[1] = "_blank";
arg[2] = 0;
object loadproperty1 = CreatePropertyValue("Hidden", true); // Executes the OpenOffice without UI
arg[3] = new Object[] { loadproperty1};
object oComponent = Invoke(oDesktop,"loadComponentFromUrl",BindingFlags.InvokeMethod,arg);
//Create an array for the storeToUrl method
arg = new Object[2];
arg[0] = PathConverter(exportfile);
object storeproperty1 = CreatePropertyValue("Overwrite", true); // Overrites if file exits and prevents errors
object storeproperty2 = CreatePropertyValue("FilterName", "HTML (StarWriter)"); // Export to HTML
arg[1] = new Object[] { storeproperty1,storeproperty2 };
Invoke(oComponent,"storeToUrl",BindingFlags.InvokeMethod,arg);
}
I published a previous solution regarding the exportformats and the string you need to pass
Helper Methods:
private static object CreatePropertyValue(object serviceManager,string name, object value)
{
object propertyvalue = Invoke(serviceManager, "Bridge_GetStruct", BindingFlags.CreateInstance|BindingFlags.InvokeMethod|BindingFlags.GetProperty,
"com.sun.star.beans.PropertyValue");
Invoke(propertyvalue, "Name", BindingFlags.SetProperty, name);
Invoke(propertyvalue, "Value", BindingFlags.SetProperty, value);
return propertyvalue;
}
private static object Invoke(object obj, string method, BindingFlags binding, params object[] par)
{
return obj.GetType().InvokeMember(method, binding, null, obj, par);
}
/// Convert into OO file format
/// The file.
/// The converted file
private static string PathConverter( string file)
{
try
{
file = file.Replace(@"\", "/");
return "file:///"+file;
}
catch (System.Exception ex)
{
throw ex;
}
}