Page 1 of 1
Open Impress doc, add slide, add text, import picture
Posted: Sun May 23, 2021 4:26 pm
by Pierre.Godot
Hello,
I am trying to implement in BASIC :
1. open an impress document
2. add a slide
3. add a text on the slide
4. import a picture to the same slide
Thank you
Re: impress basic
Posted: Sun May 23, 2021 5:01 pm
by JeJe
Here's a start for 1:
viewtopic.php?f=20&t=17075
You may find the documentation here helpful:
https://www.pitonyak.org/oo.php
Re: impress basic
Posted: Mon May 24, 2021 5:09 am
by Jurassic Pork
hello,
Pierre.Godot wrote:Hello,
I am trying to implement in BASIC :
1. open an impress document
2. add a slide
3. add a text on the slide
4. import a picture to the same slide
Thank you
hello,
here is an example to do what you want to do :
Code: Select all
Sub TestPierre()
Dim oPresDoc,oSlideList,oSlide,TxtShp,oImagen_obj,oPos,oSize as object
Dim TxtPoint as New com.sun.star.awt.Point
Dim FileName as string
Dim noArgs() 'An empty array for the arguments.
FileName = "D:\Temp\testPierre.odp"
FileName = convertToURL(FileName)
oPresDoc = StarDesktop.loadComponentFromURL(FileName, "_blank", 0, noArgs())
'get list of slides
oSlideList = oPresDoc.getDrawPages()
oSlideList.insertNewByIndex(oSlideList.getCount()) ' create new slide
oSlide = oSlideList.getByIndex(oSlideList.getCount()-1) ' select new slide
oSlide.setName("myNewSlide") ' name new slide
Set TxtShp = oPresDoc.createInstance("com.sun.star.drawing.TextShape") ' create new TextShape
oSlide.Add(TxtShp) ' insert the new TextShape in the new slide
TxtPoint.X = OSlide.Width * 0.1
TxtPoint.Y = OSlide.Height * 0.1
TxtShp.Position = TxtPoint
TxtShp.TextHorizontalAdjust = com.sun.star.drawing.TextHorizontalAdjust.LEFT
TxtShp.TextAutoGrowWidth = false
TxtShp.TextAutoGrowHeight = false
TxtShp.SetString("Here is Babe the Sheep-Pig")
oSize = TxtShp.Size
oSize.Height = 2000
oSize.Width = 23000
TxtShp.Size = oSize
TxtShp.TextFitToSize = com.sun.star.drawing.TextFitToSizeType.PROPORTIONAL
ImagenURL = convertToURL("d:\temp\babe-pig.jpg")
' create new GraphicObjectShape
oImagen_obj = ThisComponent.createInstance("com.sun.star.drawing.GraphicObjectShape")
oImagen_obj.GraphicURL = ImagenURL
oSize = oImagen_obj.Size
oSize.Height = 8000
oSize.Width = 6000
oImagen_obj.Size = oSize
oPos = oImagen_obj.Position
oPos.X = 10000
oPos.Y = 5000
oImagen_obj.Position = oPos
oSlide.add(oImagen_obj) ' insert the new GraphicObjectShape in the new slide
End Sub
tested with Impress LibreOffice 6.4.7.2. Should work with OpenOffice.
Friendly, J.P