*画像の挿入 [#s0f408aa] Writer では com.sun.star.text.TextGraphicObject を利用して画像を挿入します。 #contents **リンクとして挿入 [#j7641543] この方法ではリンクになります。 #code(ob){{ 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 }} **埋め込みとして挿入 [#ic77f8ed] リンクとしてではなく埋め込み画像としてドキュメントに同梱されるように挿入します。 #code(ob){{ 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 }} **画像のページ移動 [#n3abea38] ページにアンカーされているページを移動させます。 #code(ob){{ 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 }} ** 文字として挿入 [#bea53319] 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 |