【问题标题】:OpenOffice SDK: convert document to PDFOpenOffice SDK:将文档转换为 PDF
【发布时间】:2011-03-31 21:00:36
【问题描述】:

我正在尝试构建一个应用程序,以使用 OpenOffice SDK 将文档(word、powerpoint)转换为 PDF。

我正在使用 C++,我希望应用程序做的只是获取输入文档文件名和输出 PDF 文件名,然后进行转换。

是否有任何示例或简单的入门方法?我看到的大部分文档都使用 Java。

【问题讨论】:

  • 我处于同样的情况,理想情况下我需要开发一个 C++ 应用程序来将 xls 转换为 pdf。到目前为止,我有这样的程序在 C# 中使用 OO 3.3 工作。我还为此找到了一些 C++ 示例,但它们引用了 OO 头文件,这些头文件在 OO 的 std 安装甚至 OO SDK 中都没有提供。对此表示赞赏!

标签: c++ windows sdk openoffice.org


【解决方案1】:

您可以在此处获取示例源代码:

http://forum.openoffice.org/en/forum/viewtopic.php?t=3801

【讨论】:

    【解决方案2】:

    我是用 C# 做的,希望对大家有所帮助:

    // Connect to a running office and get the service manager
    unoidl.com.sun.star.uno.XComponentContext m_xContext = uno.util.Bootstrap.bootstrap();
    var mxMSFactory = (XMultiServiceFactory)m_xContext.getServiceManager();
    XComponentLoader desktop = (XComponentLoader)mxMSFactory.createInstance("com.sun.star.frame.Desktop");
    XComponentLoader xComponentLoader = (unoidl.com.sun.star.frame.XComponentLoader)desktop;
    PropertyValue[] properties = new PropertyValue[1];
    properties[0] = new PropertyValue();
    properties[0].Name = "Hidden";
    properties[0].Value = new uno.Any(true);
    
    XComponent xComponent = xComponentLoader.loadComponentFromURL("file:///YOUR .ODT PATH", "_blank", 0, properties);
    XTextDocument xDocument = (XTextDocument)xComponent;
    
    XStorable xStorable = (XStorable)xDocument;
    PropertyValue[] storeProps = new PropertyValue[3];
    storeProps[0] = new PropertyValue();
    storeProps[0].Name = "FilterName";
    storeProps[0].Value = new uno.Any("writer_pdf_Export");
    storeProps[1] = new PropertyValue();
    storeProps[1].Name = "Overwrite";
    storeProps[1].Value = new uno.Any(true);
    storeProps[2] = new PropertyValue();
    storeProps[2].Name = "SelectPdfVersion";
    storeProps[2].Value = new uno.Any(1);
    
    xStorable.storeToURL("file:///YOUR PDF PATH", storeProps);
    xDocument.dispose();
    

    【讨论】:

    • 我无法弄清楚这段代码。你能多描述一下吗?您使用了什么组件,以及您的程序流程如何运行?
    【解决方案3】:

    正确的开始方式是阅读Developer's Guide

    我们的业务中的好东西并不容易。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-12
      • 2015-01-09
      • 1970-01-01
      • 1970-01-01
      • 2018-01-07
      • 2017-01-13
      相关资源
      最近更新 更多