bash - 用于创建 libre office Impress 图像的 shell 脚本

标签 bash shell automation openoffice.org libreoffice

我有一些通过分析生成的图像文件。每次我进行分析时,文件名都是相同的。我必须创建一个演示文稿,并且我正在使用 Libre Office Impress。 假设我有三个图像 image1.png、image2.png 和 image3.png,我应该将这些图像放在第 3 页、第 5 页和第 8 页

现在,我正在手动插入图像。我了解非常基本的 shell 脚本。所以我想知道什么是 bash shell 脚本来自动创建一个 libre office impress 文件,并在上述页面中自动插入图像。

最佳答案

如果 .odp 文件的主要部分没有改变,可以制作一个 flat openDocument 格式的模板,其中 3 个图像的名称由脚本更新。 平面文档是未压缩的xml文档,可以使用文本编辑器打开它来谨慎手动更改某些部分。通常此类文档的名称类似于 .fodp您必须以平面格式保存此模板,并包含图像链接,而不是合并它们。

所以。 让我们说:

  • 模板位于 /path/to/the/template.fodp在示例的图像 im1.pngimg2.pngimg3.png 旁边。
  • 第一张图片的名称是image1.png ,第二个image2.png ,第三个:image3.png .
  • 要导入的图片在同一个目录 /path/to/the/document最终文件在哪里。

让我们编写一个脚本insertImages.sh

myTpl="$1" # will contains '/path/to/the/template.fodp'
myDir="$2" # will contains '/path/to/the/document'
img1="$3"  # will contains the name of the first image in myDir
img2="$4"  # will contains the name of the second image in myDir
img3="$5"  # will contains the name of the third image in myDir

[[ -f "$1" ]] && cp "$1" "$2/document.fodp" || exit 1 # checks if the template exists and copy it
[[ -f "$3" ]] && sed "$2/document.fodp" "s/img1.png/$3/" || exit 1 # overwrite the name of the first image
[[ -f "$4" ]] && sed "$2/document.fodp" "s/img2.png/$4/" || exit 1 # overwrite the name of the second image
[[ -f "$5" ]] && sed "$2/document.fodp" "s/img3.png/$5/" || exit 1 # overwrite the name of the third image

这个脚本应该这样调用:

insertImages.sh "/path/to/the/template.fodp" "/path/to/the/document" "image1.png" "image2.png" "image3.png"

我不是一个大程序员。所以这些行中可能存在一些错误。但原则是有的。

它们是一些约束:

  • 平面文档
  • 图像的相对路径。

关于bash - 用于创建 libre office Impress 图像的 shell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29884789/

相关文章:

Bash 脚本,匹配日期?

perl - stdin 上的 socat 阻塞

bash - 如何使用 For 循环重命名目录中的所有文件?

linux - 如何删除bash中的双行

android - 如何授予从 Play 商店下载的应用程序的权限?

internet-explorer - AutoHotKey 如何从 Internet Explore 中的网页获取文本

bash - 尾-F log.log | grep 响应时间 |切-d = -f 2

shell - 如何从我自己的脚本中为 fish shell 提供制表符补全?

unix - 如何监控 GitHub 存储库的更改?

ios - ios模拟器可以在windows下运行吗