dovrei riuscire ad inserire delle immagini dentro un testo in writer.
Credevo di essere riuscito a risolvere con questo codice che ho preso girovagando sul web:
Codice: Seleziona tutto
sub addimm
oDoc = thisComponent
oDrawPage = oDoc.getDrawPage()
' CHANGE ME !!!
' CHANGE ME !!!
cFile = "/home/utente/cover.jpg"
cUrl = ConvertToUrl( cFile )thisComponent
' Convert the URL into an internal URL within the document.
' If you comment out this line, then the shape that is created from the url
' will refer to the external graphic, which must always be present.
cUrl = LoadGraphicIntoDocument( oDoc, cUrl, "Cash Cow" )
' Now the URL points to a graphic *inside* of the document's Zip file,
' rather than an external url.
' Create a GraphicObjectShape.
oShape = MakeGraphicObjectShape( oDoc, MakePoint( 1500, 3000 ), MakeSize( 3000, 4000 ) )
' Add it to the drawing page.
oDrawPage.add( oShape )
' Set its URL to a particular graphic.
oShape.GraphicURL = cUrl
end sub
' Given a URL to an external graphic resource,
' load that graphic permanently into this drawing document,
' and return a new URL to the internal resource.
' The new URL can be used in place of the old URL.
Function LoadGraphicIntoDocument( oDoc As Object, cUrl As String, cInternalName As String ) As String
' Get the BitmapTable from this drawing document.
' It is a service that maintains a list of bitmaps that are internal
' to the document.
oBitmaps = oDoc.createInstance( "com.sun.star.drawing.BitmapTable" )
' Add an external graphic to the BitmapTable of this document.
oBitmaps.insertByName( cInternalName, cUrl )
' Now ask for it back.
' What we get back is an different Url that points to a graphic
' which is inside this document, and remains with the document.
cNewUrl = oBitmaps.getByName( cInternalName )
LoadGraphicIntoDocument = cNewUrl
End Function
Function MakePoint( ByVal x As Long, ByVal y As Long ) As com.sun.star.awt.Point
oPoint = createUnoStruct( "com.sun.star.awt.Point" )
oPoint.X = x
oPoint.Y = y
MakePoint = oPoint
End Function
Function MakeSize( ByVal width As Long, ByVal height As Long ) As com.sun.star.awt.Size
oSize = createUnoStruct( "com.sun.star.awt.Size" )
oSize.Width = width
oSize.Height = height
MakeSize = oSize
End Function
Function MakeRectangleShape( oDoc As Object,_
Optional oPosition As com.sun.star.awt.Point,_
Optional oSize As com.sun.star.awt.Size ) As com.sun.star.drawing.RectangleShape
oShape = oDoc.createInstance( "com.sun.star.drawing.RectangleShape" )
If Not IsMissing( oPosition ) Then
oShape.Position = oPosition
EndIf
If Not IsMissing( oSize ) Then
oShape.Size = oSize
EndIf
MakeRectangleShape = oShape
End Function
Function MakeGraphicObjectShape( oDoc As Object,_
Optional oPosition As com.sun.star.awt.Point,_
Optional oSize As com.sun.star.awt.Size ) As com.sun.star.drawing.GraphicObjectShape
oShape = oDoc.createInstance( "com.sun.star.drawing.GraphicObjectShape" )
If Not IsMissing( oPosition ) Then
oShape.Position = oPosition
EndIf
If Not IsMissing( oSize ) Then
oShape.Size = oSize
EndIf
MakeGraphicObjectShape = oShape
End Function 1) L'immagine creata con questo codice non è come un immagine inserita da menu (in parole povere se doppioclicco sopra l'immagine del documento non mi apre la finestra di dialogo immagine dove, per esempio, si può decidere l'allineamento etc etc) e a me invece servirebbe proprio una di quel tipo.
2) Forse legato al punto uno non riesco a ricavare le dimensioni dell'imagine caricata per fare un resize giusto.
Spero che qualcuno possa darmi una dritta.
Ciao
PS: Uso ubuntu 10.10, Open office 3.2.1.