OpenOffice API: сохранение документа Impress (презентации) как автономного файла

Когда я сохраняю с фильтром «MS PowerPoint 97», файлы изображений, используемые в GraphicObjectShape объектах, просто связаны, а не содержатся в файле.

Есть ли свойство этого фильтра или свойства документа, чтобы OOo создавал автономный файл (файлы изображений встроены, а не связаны)?

Изменить:

Объект XLinkageSupport имеет функцию breakLink . Есть какие-нибудь подсказки, как получить эти интерфейсы?


person vbence    schedule 18.07.2011    source источник


Ответы (1)


Вы можете вставлять изображения в OOo-документ с помощью объекта com.sun.star.drawing.BitmapTable. Следующая функция примет документ (его XMultiServiceFactory интерфейс), объект File, указывающий на файл изображения по вашему выбору, и внутреннее имя, которое должно быть уникальным, встраивает изображение и возвращает 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;
}
person vbence    schedule 29.07.2011