【问题标题】:OpenOffice API: Saving Impress (presentation) document as self-contained fileOpenOffice API:将 Impress(演示)文档保存为独立文件
【发布时间】:2011-07-18 16:20:46
【问题描述】:

当我使用“MS PowerPoint 97”过滤器保存时,GraphicObjectShape 对象中使用的图像文件只是链接,而不包含在文件中。

是否有此过滤器的属性或文档属性使 OOo 创建一个自包含文件(嵌入而不是链接的图像文件)?

编辑:

XLinkageSupport 对象有一个breakLink 函数。任何线索如何获得这些接口?

【问题讨论】:

    标签: java openoffice.org openoffice-impress


    【解决方案1】:

    您可以通过com.sun.star.drawing.BitmapTable 对象将图像嵌入到OOo 文档中。以下函数将获取文档(其XMultiServiceFactory 接口)、一个指向您选择的图像文件的File 对象和一个必须唯一的 internalName,嵌入图像并返回指向嵌入实例的 URL。

    /**
     * Embeds an image into the document and gets back the new URL.
     *
     * @param factory Factory interface of the document.
     * @param file Image file.
     * @param internalName Name of the image used inside the document.
     * @return URL of the embedded image.
     */
    public static String embedLocalImage(XMultiServiceFactory factory, File localFile, String internalName) {
    
        // future return value
        String newURL = null;
    
        // URL of the file (note that BitmapTable expects URLs starting with
        // "file://" rather than just "file:". Also note that getRawPath() will
        // return an encoded URL (with special character in the form of %xx).
        String imageURL = "file://" + localFile.toURI().getRawPath();
    
        try {
    
            // get a BitmapTable object from the document (and get interface)
            Object bitmapTable = factory.createInstance("com.sun.star.drawing.BitmapTable");
            XNameContainer bitmapContainer = (XNameContainer)UnoRuntime.queryInterface(XNameContainer.class, bitmapTable);
    
            // insert image by URL into the table
            bitmapContainer.insertByName(internalName, imageURL);
    
            // get interface
            XNameAccess bitmapAccess = (XNameAccess)UnoRuntime.queryInterface(XNameAccess.class, bitmapTable);
    
            // get the embedded URL back
            newURL = (String)bitmapAccess.getByName(internalName);
    
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    
        // return the new (embedded) url
        return newURL;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-10
      • 1970-01-01
      相关资源
      最近更新 更多