帮我看下下面这个程序, 关于 调用openoffice 将文档转化为 pdf的
namespace ConsoleApplication12
{
class Program
{
private static Mutex _openOfficeLock = new Mutex(false, "OpenOfficeMutexLock-MiloradCavic");
static void Main(string[] args)
{
bool obtained = _openOfficeLock.WaitOne(60 * 1000, false);
try
{
if (!obtained)
{
throw new System.Exception(string.Format("Request for using OpenOffice wasn't served after {0} seconds. Aborting...", 30));
} string filename =PathConverter("E:/test.doc"); PropertyValue[] propertyValues = new PropertyValue[1];
propertyValues[0] = new unoidl.com.sun.star.beans.PropertyValue();
propertyValues[0].Name = "Hidden";
propertyValues[0].Value = new uno.Any(true); //我们打开并连接一个OOo程序,这需要创建一个XComponentContext对象:
XComponentContext xContext = uno.util.Bootstrap.bootstrap(); // 创建 xFactory
XMultiServiceFactory xFactory = (XMultiServiceFactory)xContext.getServiceManager();
//创建XComponentLoader对象:
XComponentLoader xLoader = (XComponentLoader)xFactory.createInstance("com.sun.star.frame.Desktop");
// 准备开始加载文档 // Preparing properties for loading the document
// load begin
XComponent xComponent = xLoader.loadComponentFromURL(filename, "_blank", 0, propertyValues);
//Wait for loading
while (xComponent == null)
{
System.Threading.Thread.Sleep(3000);
}
string outputFilePath = PathConverter("E:/test.pdf");
saveDocument(xComponent, outputFilePath); xComponent.dispose();
}
catch (System.Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
Process[] pt = Process.GetProcessesByName("soffice.bin");
if (pt != null && pt.Length > 0)
pt[0].Kill(); Process[] ps = Process.GetProcessesByName("C:\\Program Files\\OpenOffice.org 3\\program\\soffice.exe");
if (ps != null && ps.Length > 0)
ps[0].Kill();
Console.ReadKey();
}
}
private static void saveDocument(XComponent xComponent, string fileName)
{ unoidl.com.sun.star.beans.PropertyValue[] propertyValue2 =
new unoidl.com.sun.star.beans.PropertyValue[2];
propertyValue2[0] = new unoidl.com.sun.star.beans.PropertyValue();
propertyValue2[0].Name = "Overwrite";
propertyValue2[0].Value = new uno.Any(true);
propertyValue2[1] = new unoidl.com.sun.star.beans.PropertyValue();
propertyValue2[1].Name = "FilterName";
propertyValue2[1].Value = new uno.Any("writer_pdf_Export"); ((XStorable)xComponent).storeToURL(fileName, propertyValue2);
} private static string PathConverter(string file)
{
try
{
file = file.Replace(@"\", "/"); return "file:///" + file;
}
catch (System.Exception ex)
{
throw ex;
}
} }
}红色部分执行不过去呢!
namespace ConsoleApplication12
{
class Program
{
private static Mutex _openOfficeLock = new Mutex(false, "OpenOfficeMutexLock-MiloradCavic");
static void Main(string[] args)
{
bool obtained = _openOfficeLock.WaitOne(60 * 1000, false);
try
{
if (!obtained)
{
throw new System.Exception(string.Format("Request for using OpenOffice wasn't served after {0} seconds. Aborting...", 30));
} string filename =PathConverter("E:/test.doc"); PropertyValue[] propertyValues = new PropertyValue[1];
propertyValues[0] = new unoidl.com.sun.star.beans.PropertyValue();
propertyValues[0].Name = "Hidden";
propertyValues[0].Value = new uno.Any(true); //我们打开并连接一个OOo程序,这需要创建一个XComponentContext对象:
XComponentContext xContext = uno.util.Bootstrap.bootstrap(); // 创建 xFactory
XMultiServiceFactory xFactory = (XMultiServiceFactory)xContext.getServiceManager();
//创建XComponentLoader对象:
XComponentLoader xLoader = (XComponentLoader)xFactory.createInstance("com.sun.star.frame.Desktop");
// 准备开始加载文档 // Preparing properties for loading the document
// load begin
XComponent xComponent = xLoader.loadComponentFromURL(filename, "_blank", 0, propertyValues);
//Wait for loading
while (xComponent == null)
{
System.Threading.Thread.Sleep(3000);
}
string outputFilePath = PathConverter("E:/test.pdf");
saveDocument(xComponent, outputFilePath); xComponent.dispose();
}
catch (System.Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
Process[] pt = Process.GetProcessesByName("soffice.bin");
if (pt != null && pt.Length > 0)
pt[0].Kill(); Process[] ps = Process.GetProcessesByName("C:\\Program Files\\OpenOffice.org 3\\program\\soffice.exe");
if (ps != null && ps.Length > 0)
ps[0].Kill();
Console.ReadKey();
}
}
private static void saveDocument(XComponent xComponent, string fileName)
{ unoidl.com.sun.star.beans.PropertyValue[] propertyValue2 =
new unoidl.com.sun.star.beans.PropertyValue[2];
propertyValue2[0] = new unoidl.com.sun.star.beans.PropertyValue();
propertyValue2[0].Name = "Overwrite";
propertyValue2[0].Value = new uno.Any(true);
propertyValue2[1] = new unoidl.com.sun.star.beans.PropertyValue();
propertyValue2[1].Name = "FilterName";
propertyValue2[1].Value = new uno.Any("writer_pdf_Export"); ((XStorable)xComponent).storeToURL(fileName, propertyValue2);
} private static string PathConverter(string file)
{
try
{
file = file.Replace(@"\", "/"); return "file:///" + file;
}
catch (System.Exception ex)
{
throw ex;
}
} }
}红色部分执行不过去呢!
[map_to_uno():unoidl.com.sun.star.beans.PropertyValue.Value [map_to_uno():any] could not convert type!不明白啊,从网上找了很多资料 参数都是这么写的,到这就不好用了呢!