Lars ,
oShape.GraphicURL = sURL
oGraph.GraphicURL = sURL
here you makes the mistake, if you want that the graphic is embedded in
the document you need a internal URL and there for we uses the URL who
points to the Oshape so just change
oGraph.GraphicURL = sURL to oGraph.GraphicURL = oShape.GraphicURL
hope it helps
Fernand
Hi
I have a problem I'm trying to solve. I want to add an image to a
template when the templates scripÄt is executed after pressing an OK
button. The image is addes as I want it's scaled to the right
dimentions but when I save he template with another name and send the
document as an attachment to an email the receiver can't view the
image. This because the actual image isn't stored, rather the URL path
(file:///<path>/filename.jpg) is stored instead. When the receiver
opens the document the path is also changes
Here's the code where I add the image (oGraph with help of an oShape),
the o is to emphesise that it is refrensed objects and ordinary types.
I have added some comments to try to explain what I do. I'm not sure
if I understand exactly what I do. I've only programmed Writer Basic
Scripts for a week.
'Global referense to a cursor
Private Sub UserForm_DragGraph(oDoc As Object, oText as Object, oTable
As Object, oCursor As Object)
' Since Basic doesn't handle exceptions like C++, C#, Delphi nad ADA
on error goto UserForm_DragGraph_Error
Dim oShape As Object
Dim oGraph As Object
Dim oImageSize As Object
Dim oCell As Object
Dim iRelation As Double
Dim sURL As String
Dim oUnoUrl As Object
' Get teh path and file name for the image
sURL = UserForm_GetLogotypeName()
' Create an shape object, we need this this to get the right
dimention for the
' image we want to add.
oShape = oDoc.createInstance("com.sun.star.drawing.GraphicObjectShape")
' Create the the image as a graphic object. This object is added to
the
' document.
oGraph = oDoc.createInstance("com.sun.star.text.GraphicObject")
' Get the cell where the image is positioned
oCell = oTable.getCellByPosition( 0, 0 )
' Draw the temporarilly spape in the document. The shape we use to
get the right
' size of the image. This shape/image is later removed from the
document
oDoc.getDrawPage().add(oShape)
' Set the URL for oShape and oGraph. Of course it is the very same
picture we use-
oShape.GraphicURL = sURL
oGraph.GraphicURL = sURL
' In stead of creating a new oImageSize object we us the (object)
instans created by oShape.
oImageSize = oShape.getSize()
' In stead of using the mm size we use the pixel size for rescaling
the image
' for some reason the mm size was zoro resulting in divition by zero.
oImageSize.Height = oShape.Graphic.SizePixel.Height
oImageSize.Width = oShape.Graphic.SizePixel.Width
' Now scale the image
oImageSize.Height = 1620
oImageSize.Width = 1620 * iRelation
' Set the sixe of the image/graph that we want to use in the ducument
oGraph.setSize(oImageSize)
' Assign a text object that refers to the actual text
' Probaly not nessasarilly
oText= oDoc.getText()
oGraph.AnchorType = com.sun.star.text.TextContentAnchorType.AS_CHARACTER
' Get the referens to the text where we want to place the image
(oGraph)
oText = oCell.getText()
' Create a cursor
oCursor = oText.createTextCursor()
' Now we insert the oGraph object we crated. Indered at the postion
oCursor.
oText.insertTextContent(oCursor, oGraph, false)
' Now remove the temporarilly object shape that we added at the
start of this sub
oDoc.getDrawPage().remove(oShape)
Exit Sub
UserForm_DragGraph_Error:
Exit Sub
End Sub '''' UserForm_DragGraph
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@api.openoffice.org
For additional commands, e-mail: dev-h...@api.openoffice.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@api.openoffice.org
For additional commands, e-mail: dev-h...@api.openoffice.org