Picture disappears in OpenOffice after deleting linked file

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
Lumberjack
Posts: 13
Joined: Thu Jan 28, 2021 4:02 pm

Picture disappears in OpenOffice after deleting linked file

Post by Lumberjack »

Hi

I using Apache OpenOffice. I have problem with picture inserted programmatically. All is work fine. Picture is pasted into document . But If delete picture file from a disc , picture disappeard from document (it's remain only path to the picture). If using LibreOffice its work fine. What should i change in ma code.

My code bellow :

Code: Select all

 // pict - path to image file in format file:///
 private void InsertPicture(XComponent oDoc, XTextRange range, string pict, int width, int height)
        {
            int pro = 27;
            int imgwid = width * pro;
            int imght = height * pro;

            unoidl.com.sun.star.container.XNameContainer xBitmapContainer = null;
            unoidl.com.sun.star.text.XText xText = range.getText();
            unoidl.com.sun.star.text.XTextContent xImage = null;

            unoidl.com.sun.star.lang.XMultiServiceFactory servfac = (unoidl.com.sun.star.lang.XMultiServiceFactory)oDoc;

            xBitmapContainer = (unoidl.com.sun.star.container.XNameContainer)servfac.createInstance("com.sun.star.drawing.BitmapTable");

            xImage = (unoidl.com.sun.star.text.XTextContent)servfac.createInstance("com.sun.star.text.TextGraphicObject");

            unoidl.com.sun.star.beans.XPropertySet xprops = (unoidl.com.sun.star.beans.XPropertySet)xImage;

            object GraphicObj = servfac.createInstance("com.sun.star.text.GraphicObject");

            xprops.setPropertyValue("GraphicURL", new uno.Any(pict));
            xprops.setPropertyValue("Width", new uno.Any(imgwid));
            xprops.setPropertyValue("Height", new uno.Any(imght));
            xprops.setPropertyValue("AnchorType", new uno.Any(typeof(unoidl.com.sun.star.text.TextContentAnchorType), unoidl.com.sun.star.text.TextContentAnchorType.AS_CHARACTER));
            //
            //   selRange.
            xText.insertTextContent(range, xImage, true);
          //  xText.
        }

 Edit: Discussion about using UNO services in C# continues in topic Use createUnoService in C# 
-- MrProgrammer, forum moderator 
OpenOffice 3.1 on Windows Vista
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: Disappeard picture in Apache OpenOffice

Post by JeJe »

If you look at Useful Macro Information For OpenOffice By Andrew Pitonyak he has a section on how to Convert a linked graphic to an embedded graphic.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
Mr.Dandy
Posts: 427
Joined: Tue Dec 11, 2012 4:22 pm

Re: Disappeard picture in Apache OpenOffice

Post by Mr.Dandy »

Lumberjack wrote: But If delete picture file from a disc , picture disappeard from document
Configuration issue.
Picture is not embedded in the document but just linked.
OpenOffice 4.1.12 - Windows 10
Post Reply