通过命令行填充图片的演示文件的背景

时间:2018-01-23 09:38:35

标签: command-line libreoffice libreoffice-impress

我想在libreOffice Impress演示文稿中使用一些jpeg作为背景图片。但是我不想通过幻灯片添加它们。

有没有办法使用(Linux)命令行将图片添加到演示文稿文件中?

类似的东西:

for i in *.jpg; do <add a new slide with that jpg as background to the presentation file>; done

1 个答案:

答案 0 :(得分:0)

在LibreOffice中,转到工具 - &gt;宏 - &gt;组织宏 - &gt; LibreOffice Basic 并将以下宏添加到Module1

Sub InsertSlideWithBackgroundImage(imageFilePath)
    imageFileURL = ConvertToURL(imageFilePath)
    oDoc = ThisComponent
    oBackground = oDoc.createInstance("com.sun.star.drawing.Background")
    oBitmaps = ThisComponent.createInstance( "com.sun.star.drawing.BitmapTable")
    iBitmap = 1
    Do
        sBitmapName = "bk" & iBitmap
        iBitmap = iBitmap + 1
    Loop Until Not oBitmaps.hasByName(sBitmapName)
    oBitmaps.insertByName(sBitmapName, imageFileURL)
    oBackground.FillStyle = com.sun.star.drawing.FillStyle.BITMAP
    oBackground.FillBitmapURL = oBitmaps.getByName(sBitmapName)
    oSlideList = oDoc.getDrawPages()
    oSlide = oSlideList.insertNewByIndex(oSlideList.Count)
    oSlide.Background = oBackground
End Sub

然后从命令行添加图像。

loimpress "file.odp" "macro:///Standard.Module1.InsertSlideWithBackgroundImage(image.jpg)"

或者,从命令行运行python3并与LibreOffice的侦听实例进行交互。这种方法在http://christopher5106.github.io/office/2015/12/06/openoffice-libreoffice-automate-your-office-tasks-with-python-macros.html解释。

修改

要直接运行它,请传递图像的文件路径。

Sub Test1
    Call InsertSlideWithBackgroundImage("/path/to/your_image.jpg")
End Sub