使用 C# 反射或 perl 自动打开 OpenOffice Impress 格式并将其保存为 html/jpeg

发布于 2024-07-25 19:00:47 字数 245 浏览 5 评论 0原文

我想要转换 OpenOffice Impress 演示文稿文件并将其转换为 HTML 或 JPEG。

我找到了一些例子,但它们似乎被破坏了。 我想这样做,安装什么版本的 OpenOffice 并不重要,并且我不想将任何互操作 dll 与我的应用程序捆绑在一起。 因此,我正在寻找一种最好是在 C# 反射中完成的解决方案,或者使用 Win32-OLE 的 Perl 完成的解决方案。

另外,如何隐藏 OpenOffice GUI?

I want to convert an OpenOffice Impress Presentation file and convert it to HTML or JPEG.

I have found a few examples, but they appear to be broken. I would like to do it, in a way that it does not matter what version of OpenOffice is installed, and I do not want to bundle any interop dlls with my application. Therefore, I am looking for a solution that is done in C# reflection, preferably, or Perl using Win32-OLE.

Also, how would you hide the OpenOffice GUI?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

嗼ふ静 2024-08-01 19:00:47

看看这个解决方案。 可能需要对 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);
}

我发布了有关导出格式和需要传递

帮助程序方法的字符串的先前解决方案:

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;  
      } 

   }

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;  
      } 

   }
心如荒岛 2024-08-01 19:00:47

使用 OpenOffice::OODoc,它理解 XML 格式OpenOffice 文档,不需要运行 openoffice 二进制文件,甚至不需要安装 openoffice。

Use OpenOffice::OODoc, it understands the XML format of OpenOffice documents, requires no openoffice binaries to be running or even to have openoffice installed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文