Re: [api-dev] Create blank document and insert image into it [JAVA]
Ariel Constenla-Haile wrote: Hello Михаил, On Sunday 08 February 2009 13:17, Михаил Кечинов wrote: Hello. I need to insert image into opened document in java program. I am creating document: === com.sun.star.frame.XComponentLoader xComponentLoader = null; com.sun.star.beans.PropertyValue openProperties[] = new com.sun.star.beans.PropertyValue[1]; openProperties[0] = new com.sun.star.beans.PropertyValue(); openProperties[0].Name = Hidden; openProperties[0].Value = new Boolean(true); try { xComponentLoader = (com.sun.star.frame.XComponentLoader)UnoRuntime.queryInterface(com.sun.star .frame.XComponentLoader.class, this.xDesktop); this.xComponent = xComponentLoader.loadComponentFromURL(private:factory/swriter, _blank, 0, openProperties); } catch( Exception e) { System.err.println(Could not create blank file.); e.printStackTrace(System.err); return false; } === What next? well... study the SDK examples. Did you download the SDK? See http://svn.services.openoffice.org/opengrok/xref/DEV300_m41/odk/examples/java/Text/GraphicsInserter.java it's also on your SDK. Regards -- Ariel Constenla-Haile La Plata, Argentina Aus der Kriegsschule des Lebens - Was mich nicht umbringt, macht mich härter. Nietzsche Götzendämmerung, Sprüche und Pfeile, 8. - To unsubscribe, e-mail: dev-unsubscr...@api.openoffice.org For additional commands, e-mail: dev-h...@api.openoffice.org but what if the document is not really new? i mean, it already has contents and the image must be inserted from where the cursor is. - What cannot kill you will make you stronger. -- View this message in context: http://www.nabble.com/Create-blank-document-and-insert-image-into-it--JAVA--tp21899867p22397452.html Sent from the openoffice - api dev mailing list archive at Nabble.com. - To unsubscribe, e-mail: dev-unsubscr...@api.openoffice.org For additional commands, e-mail: dev-h...@api.openoffice.org
Re: [api-dev] Create blank document and insert image into it [JAVA]
Hello allirpa, On Sunday 08 March 2009, 10:25, allirpa wrote: but what if the document is not really new? i mean, it already has contents and the image must be inserted from where the cursor is. I assume you're talking about a Writer document, and the cursor is the blinking insertion point. If so, some people use the ViewCursor. IMHO the following is the safer way if you do not want to insert anything when the user has selected something (code in OOo Basic, do yourself the Java translation): Sub Main Dim oDoc as Object oDoc = ThisComponent Dim oController as Object oController = oDoc.getCurrentController() Dim oSelection as Object oSelection = oController.getSelection() If NOT IsNull(oSelection) and oSelection.supportsService(com.sun.star.text.TextRanges) Then If oSelection.getCount() = 1 Then Dim oTextRange as Object, oText as Object oTextRange = oSelection.getByIndex(0) oText = oTextRange.getText() Dim oTextCursor as Object oTextCursor = oText.createTextCursorByRange(oTextRange) If oTextCursor.isCollapsed() Then Dim oGraphic as Object oGraphic = insertGraphic(oDoc, oTextCursor, _ convertToURL(/home/arielfed/Imágenes/Accelerators.xcu.assertion.png)) End If End If End If End Sub Function insertGraphic( oDoc as com.sun.star.text.XTextDocument, _ oCursor as com.sun.star.text.XTextCursor,_ sURL$) On Error Resume Next Dim oGraphic as Object Dim oGraphicProvider as Object oGraphicProvider = createUnoService(com.sun.star.graphic.GraphicProvider) Dim aMediaProperties (0)as new com.sun.star.beans.PropertyValue aMediaProperties(0).Name = URL aMediaProperties(0).Value = sURL oGraphic = oGraphicProvider.queryGraphic(aMediaProperties()) Dim oGraphicShape as Object oGraphicShape = oDoc.createInstance(com.sun.star.drawing.GraphicObjectShape) Dim aSize as New com.sun.star.awt.Size aSize.Width = 3000 aSize.Height = 2000 oGraphicShape.setSize( aSize ) oCursor.getText().insertTextContent(oCursor, oGraphicShape, False) oGraphicShape.setPropertyValue(Graphic, oGraphic) insertGraphic = oGraphicShape End Function Regards -- Ariel Constenla-Haile La Plata, Argentina Aus der Kriegsschule des Lebens - Was mich nicht umbringt, macht mich härter. Nietzsche Götzendämmerung, Sprüche und Pfeile, 8. - To unsubscribe, e-mail: dev-unsubscr...@api.openoffice.org For additional commands, e-mail: dev-h...@api.openoffice.org
[api-dev] Create blank document and insert image into it [JAVA]
Hello. I need to insert image into opened document in java program. I am creating document: === com.sun.star.frame.XComponentLoader xComponentLoader = null; com.sun.star.beans.PropertyValue openProperties[] = new com.sun.star.beans.PropertyValue[1]; openProperties[0] = new com.sun.star.beans.PropertyValue(); openProperties[0].Name = Hidden; openProperties[0].Value = new Boolean(true); try { xComponentLoader = (com.sun.star.frame.XComponentLoader)UnoRuntime.queryInterface(com.sun.star.frame.XComponentLoader.class, this.xDesktop); this.xComponent = xComponentLoader.loadComponentFromURL(private:factory/swriter, _blank, 0, openProperties); } catch( Exception e) { System.err.println(Could not create blank file.); e.printStackTrace(System.err); return false; } === What next? -- Михаил Кечинов http://www.mkechinov.ru
Re: [api-dev] Create blank document and insert image into it [JAVA]
Hello Михаил, On Sunday 08 February 2009 13:17, Михаил Кечинов wrote: Hello. I need to insert image into opened document in java program. I am creating document: === com.sun.star.frame.XComponentLoader xComponentLoader = null; com.sun.star.beans.PropertyValue openProperties[] = new com.sun.star.beans.PropertyValue[1]; openProperties[0] = new com.sun.star.beans.PropertyValue(); openProperties[0].Name = Hidden; openProperties[0].Value = new Boolean(true); try { xComponentLoader = (com.sun.star.frame.XComponentLoader)UnoRuntime.queryInterface(com.sun.star .frame.XComponentLoader.class, this.xDesktop); this.xComponent = xComponentLoader.loadComponentFromURL(private:factory/swriter, _blank, 0, openProperties); } catch( Exception e) { System.err.println(Could not create blank file.); e.printStackTrace(System.err); return false; } === What next? well... study the SDK examples. Did you download the SDK? See http://svn.services.openoffice.org/opengrok/xref/DEV300_m41/odk/examples/java/Text/GraphicsInserter.java it's also on your SDK. Regards -- Ariel Constenla-Haile La Plata, Argentina Aus der Kriegsschule des Lebens - Was mich nicht umbringt, macht mich härter. Nietzsche Götzendämmerung, Sprüche und Pfeile, 8. - To unsubscribe, e-mail: dev-unsubscr...@api.openoffice.org For additional commands, e-mail: dev-h...@api.openoffice.org
Re: [api-dev] Create blank document and insert image into it [JAVA]
Thanks. As what I need. 2009/2/8 Ariel Constenla-Haile ariel.constenla.ha...@googlemail.com Hello Михаил, On Sunday 08 February 2009 13:17, Михаил Кечинов wrote: Hello. I need to insert image into opened document in java program. I am creating document: === com.sun.star.frame.XComponentLoader xComponentLoader = null; com.sun.star.beans.PropertyValue openProperties[] = new com.sun.star.beans.PropertyValue[1]; openProperties[0] = new com.sun.star.beans.PropertyValue(); openProperties[0].Name = Hidden; openProperties[0].Value = new Boolean(true); try { xComponentLoader = (com.sun.star.frame.XComponentLoader)UnoRuntime.queryInterface(com.sun.star .frame.XComponentLoader.class, this.xDesktop); this.xComponent = xComponentLoader.loadComponentFromURL(private:factory/swriter, _blank, 0, openProperties); } catch( Exception e) { System.err.println(Could not create blank file.); e.printStackTrace(System.err); return false; } === What next? well... study the SDK examples. Did you download the SDK? See http://svn.services.openoffice.org/opengrok/xref/DEV300_m41/odk/examples/java/Text/GraphicsInserter.java it's also on your SDK. Regards -- Ariel Constenla-Haile La Plata, Argentina Aus der Kriegsschule des Lebens - Was mich nicht umbringt, macht mich härter. Nietzsche Götzendämmerung, Sprüche und Pfeile, 8. - To unsubscribe, e-mail: dev-unsubscr...@api.openoffice.org For additional commands, e-mail: dev-h...@api.openoffice.org -- Михаил Кечинов http://www.mkechinov.ru