How to insert image with api without file path? because when i delete the image from that path it does not show in Presentation??
any solution for that??
Thanks
[Solved] How to insert image with api without file path ?
-
hussainreo
- Posts: 13
- Joined: Tue Apr 10, 2012 6:46 am
[Solved] How to insert image with api without file path ?
Last edited by hussainreo on Wed Apr 11, 2012 7:07 am, edited 1 time in total.
OpenOffice 3.3
Re: How to insert image with api without file path ?
This extension embeds all linked images. http://extensions.services.openoffice.o ... esEmbedder
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Re: How to insert image with api without file path ?
Hello,
to do it by code, this works for a calc document:
R
to do it by code, this works for a calc document:
Code: Select all
sub embed_bitmap
Dim Point As New com.sun.star.awt.Point
Dim Size As New com.sun.star.awt.Size
Url_Bitmap=converttourl("C:\Users\mypicture.jpg")
odoc = thiscomponent
oshape = odoc.createInstance("com.sun.star.drawing.GraphicObjectShape")
size.width = 5000
size.Height =7000
point.Y = 2000
point.X = 5000
with oshape
.name = "Shape1"
.size = size
.position = point()
.GraphicURL = Url_Bitmap
end with
opage = odoc.sheets(0).drawpage
opage.add(oshape)
'embed the picture
oBitmap = odoc.createInstance( "com.sun.star.drawing.BitmapTable" )
sName = oshape.LinkDisplayName
If oBitMap.hasByName(sName) Then
oBitmap.replaceByName( sName, oshape.GraphicURL )
else
oBitmap.insertByName( sName, oshape.GraphicURL )
End If
oNewURL = oBitmap.getByName( sName )
oshape.GraphicURL = oNewURL 'Embedded
end sub- MMove 1.0.6
- Extension for easy, exact positioning of shapes, pictures, controls, frames ...
- my current system
- Windows 11 AOO, LO | Linux Mint AOO, LO
-
hussainreo
- Posts: 13
- Joined: Tue Apr 10, 2012 6:46 am
Re: How to insert image with api without file path ?
thanks i done it ..................
OpenOffice 3.3
Re: [Solved] How to insert image with api without file path
What did you do?
R
R
- MMove 1.0.6
- Extension for easy, exact positioning of shapes, pictures, controls, frames ...
- my current system
- Windows 11 AOO, LO | Linux Mint AOO, LO
Re: [Solved] How to insert image with api without file path
Here is quick java example implementation of the solution above
Code: Select all
/*EmbedBitmap.java*/
package libreoffice;
import com.sun.star.awt.Point;
import com.sun.star.awt.Size;
import com.sun.star.beans.XPropertySet;
import com.sun.star.comp.helper.Bootstrap;
import com.sun.star.container.XNameContainer;
import com.sun.star.drawing.XShape;
import com.sun.star.frame.XComponentLoader;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.text.XText;
import com.sun.star.text.XTextContent;
import com.sun.star.text.XTextCursor;
import com.sun.star.text.XTextDocument;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
public class EmbedBitmap {
public static void main(String args[]) {
try {
/* bootstrap UNO and get the remote component context. The context can
be used to get the service manager */
XComponentContext context = Bootstrap.bootstrap();
System.out.println("Connected to openoffice process...");
// get the service manager
XMultiComponentFactory mcf = context.getServiceManager();
/* A desktop environment contains tasks with one or more
frames in which components can be loaded. Desktop is the
environment for components which can instantiate within
frames. */
Object desktop = mcf.createInstanceWithContext(
"com.sun.star.frame.Desktop", context);
XComponentLoader componentLdr =
(XComponentLoader)UnoRuntime.queryInterface(
XComponentLoader.class, desktop);
// Load a Writer document, which will be automatically displayed
XComponent writerDocument = componentLdr.loadComponentFromURL(
"private:factory/swriter", "_blank", 0,
new com.sun.star.beans.PropertyValue[0]);
// Querying for the text interface
XTextDocument docText = (XTextDocument)UnoRuntime.queryInterface(
XTextDocument.class, writerDocument);
// Querying for the text service factory
XMultiServiceFactory docServiceFactory =
(XMultiServiceFactory)UnoRuntime.queryInterface(
XMultiServiceFactory.class, docText);
// Creating graphic shape service
Object graphicShape = null;
graphicShape = docServiceFactory.createInstance(
"com.sun.star.drawing.GraphicObjectShape");
// Customizing graphic shape position and size
XShape shapeSettings = (XShape)UnoRuntime.queryInterface(
XShape.class, graphicShape);
shapeSettings.setSize(new Size(4680, 5080));
shapeSettings.setPosition(new Point(20, 20));
// Creating bitmap container service
XNameContainer bitmapContainer = UnoRuntime.queryInterface(
XNameContainer.class,
docServiceFactory.createInstance(
"com.sun.star.drawing.BitmapTable"));
// Inserting test image to the container
bitmapContainer.insertByName("testimg",
"file:///home/john/pict/testimg.bmp");
// Querying property interface for the graphic shape service
XPropertySet xPropSet = (XPropertySet)UnoRuntime.queryInterface(
XPropertySet.class, graphicShape);
System.out.println("Test img url is" +
bitmapContainer.getByName("testimg"));
// Assign test image internal URL to the graphic shape property
xPropSet.setPropertyValue("GraphicURL",
bitmapContainer.getByName("testimg"));
// Getting text field interface
XText text = docText.getText();
// Getting text cursor
XTextCursor xTextCursor = text.createTextCursor();
// Convert graphic shape to the text content item
XTextContent xTextContent = (XTextContent)UnoRuntime.queryInterface(
XTextContent.class, graphicShape);
// Embed image into the document text with replacement
System.out.println("Inserting image...");
text.insertTextContent(xTextCursor, xTextContent, true);
System.exit(0);
} catch(Exception e) {
e.printStackTrace(System.err);
System.exit(1);
}
}
}
LibreOffice 3.5 on Ubuntu 12.04