画像の挿入 
Writer では com.sun.star.text.TextGraphicObject を利用して画像を挿入します。
リンクとして挿入 
この方法ではリンクになります。
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| | Sub textgraphic_1
oDoc = ThisComponent
oText = oDoc.getText()
oViewCursor = oDoc.getCurrentController().getViewCursor()
Dim aSize As New com.sun.star.awt.Size
aSize.Width = 1000
aSize.Height = 1000
oGraphic = oDoc.createInstance("com.sun.star.text.TextGraphicObject")
oGraphic.GraphicURL = "file:///C:/usr/current_16.png"
oGraphic.Size = aSize
oText.insertTextContent(oViewCursor,oGraphic,False)
End Sub
|
埋め込みとして挿入 
リンクとしてではなく埋め込み画像としてドキュメントに同梱されるように挿入します。
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
| | Sub insertTextGraphic_2
oDoc = ThisComponent
oText = oDoc.getText()
oGP = CreateUnoService("com.sun.star.graphic.GraphicProvider")
Dim aArgs(0) As New com.sun.star.beans.PropertyValue
sGraphicURL = "file:///C:/usr/img.png"
aArgs(0).Name = "URL"
aArgs(0).Value = sGraphicURL
oGraphic = oGP.queryGraphic(aArgs)
oTextGraphic = oDoc.createInstance( _
"com.sun.star.text.TextGraphicObject")
oTextGraphic.Graphic = oGraphic
aSize = oGraphic.Size
aSize.Width = CLng((aSize.Width / 96.0) * 2540.0)
aSize.Height = CLng((aSize.Height / 96.0) * 2540.0)
oTextGraphic.setSize(aSize)
oText.insertTextContent(oText.getEnd(),oTextGraphic,False)
End Sub
|
画像のページ移動 
ページにアンカーされているページを移動させます。
0
1
2
3
4
5
6
7
8
9
10
11
12
| | Sub GraphicToNextPage
oDoc = ThisComponent
oGraphics = oDoc.getGraphicObjects()
For i = 0 To oGraphics.getCount() -1 step 1
oGraphic = oGraphics.getByIndex(i)
If oGraphic.AnchorType = com.sun.star.text.TextContentAnchorType.AT_PAGE Then
nPage = oGraphic.AnchorPageNo
oGraphic.AnchorPageNo = nPage + 1
End If
Next
End Sub
|
文字として挿入 
Sub textgraphic_11
oDoc = ThisComponent
oText = oDoc.getText()
oViewCursor = oDoc.getCurrentController().getViewCursor()
Dim aSize As New com.sun.star.awt.Size
aSize.Width = 1000
aSize.Height = 1000
oGraphic = oDoc.createInstance("com.sun.star.text.TextGraphicObject")
oGraphic.GraphicURL = "file:///home/asuka/Documents/images/q.png"
oGraphic.Size = aSize
oGraphic.AnchorType = com.sun.star.text.TextContentAnchorType.AS_CHARACTER
oText.insertTextContent(oViewCursor,oGraphic,False)
End Sub