[Libreoffice-bugs] [Bug 121536] New: Embedding external (links) images programmatically no longer works

bugzilla-daemon at bugs.documentfoundation.org bugzilla-daemon at bugs.documentfoundation.org
Tue Nov 20 04:38:27 UTC 2018


https://bugs.documentfoundation.org/show_bug.cgi?id=121536

            Bug ID: 121536
           Summary: Embedding external (links) images programmatically no
                    longer works
           Product: LibreOffice
           Version: 6.1.0.3 release
          Hardware: All
                OS: All
            Status: UNCONFIRMED
          Severity: normal
          Priority: medium
         Component: Writer
          Assignee: libreoffice-bugs at lists.freedesktop.org
          Reporter: ikharus at hotmail.com

Before 6.1.0.3, it was possible to embed all external (linked) images into a
document programmatically using the following function: 

  public static void convertLinkedImagesToEmbeded(XComponent document) throws
Exception {

    XTextGraphicObjectsSupplier graphicObjSupplier =
        (XTextGraphicObjectsSupplier)
            UnoRuntime.queryInterface(XTextGraphicObjectsSupplier.class,
document);
    XNameAccess nameAccess = graphicObjSupplier.getGraphicObjects();
    String[] names = nameAccess.getElementNames();
    for (int i = 0; i < names.length; i++) {
      Any xImageAny = (Any) nameAccess.getByName(names[i]);
      Object xImageObject = xImageAny.getObject();
      XTextContent xImage = (XTextContent) xImageObject;
      XServiceInfo xInfo = (XServiceInfo)
UnoRuntime.queryInterface(XServiceInfo.class, xImage);
      if (xInfo.supportsService("com.sun.star.text.TextGraphicObject")) {
        XPropertySet xPropSet =
            (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
xImage);
        String name = xPropSet.getPropertyValue("LinkDisplayName").toString();
        String graphicURL = xPropSet.getPropertyValue("GraphicURL").toString();
        // only ones that are not embedded
        if (graphicURL.indexOf("vnd.sun.") == -1) {
          XMultiServiceFactory multiServiceFactory =
              (XMultiServiceFactory)
                  UnoRuntime.queryInterface(XMultiServiceFactory.class,
document);
          XNameContainer xBitmapContainer =
              (XNameContainer)
                  UnoRuntime.queryInterface(
                      XNameContainer.class,
                     
multiServiceFactory.createInstance("com.sun.star.drawing.BitmapTable"));
          if (!xBitmapContainer.hasByName(name)) {
            xBitmapContainer.insertByName(name, graphicURL);
            String newGraphicURL = xBitmapContainer.getByName(name).toString();
            xPropSet.setPropertyValue("GraphicURL", newGraphicURL);
          }
        }
      }
    }
  }

I have read a lot about the image handling rework and I know that the
GraphicURL property can no longer be used for that but I couldn't find a way to
make the function work again. All the examples available out there that show
how to programmatically break links use the property GraphicURL and the
documentation only tell us to use Graphic instead of GraphicURL, but that
doesn't work in this particular case. After several hours of trying to make it
work, give up!

So, is it still possible to programatically embed linked images since 6.1.0.3+
?? What changes should I make to the function above to support both the
6.1.0.3+ and previous versions ?

Many thanks.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/libreoffice-bugs/attachments/20181120/ffa1b178/attachment-0001.html>


More information about the Libreoffice-bugs mailing list