0

我有一些 jpeg 我想在 libreOffice Impress 演示文稿中用作背景图片。但我不喜欢逐张添加它们。

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

就像是:

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

1 回答 1

0

在 LibreOffice 中,转到工具 -> 宏 -> 组织宏 -> 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
于 2018-01-23T18:11:03.740 回答