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 |