帮我看下下面这个程序, 关于 调用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;
            }
        }    }
}红色部分执行不过去呢!

解决方案 »

  1.   

      可能是FilePath转换成file:///....时的问题,代码是没错的。。提示什么错误呢。。对于Office用WPS转换好点,我见过最完美的是Adobe的AcrobatPro,但是收费
      

  2.   

    报的错是:map_to_uno():[]com.sun.star.beans.PropertyValue] conversion failed
     [map_to_uno():unoidl.com.sun.star.beans.PropertyValue.Value [map_to_uno():any] could not convert type!不明白啊,从网上找了很多资料 参数都是这么写的,到这就不好用了呢!
      

  3.   

    结贴了原来是我dll版本的问题 新的 3.4.1 sdk 不能那么弄了 哎~
      

  4.   

    哥们能使OpenOffice绿色化免安装吗?我测试过 如果不安装 c#调用时出现错误 提示:参数不对。但绝对不是参数问题,哥们有解决办法吗?