Page 1 of 1

Picture disappears in OpenOffice after deleting linked file

Posted: Fri Apr 22, 2022 10:59 am
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 

Re: Disappeard picture in Apache OpenOffice

Posted: Fri Apr 22, 2022 7:00 pm
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.

Re: Disappeard picture in Apache OpenOffice

Posted: Sat Apr 23, 2022 6:21 pm
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.