【问题标题】:shell script to create libre office Impress with images使用图像创建 libre office Impress 的 shell 脚本
【发布时间】:2015-04-26 23:20:15
【问题描述】:

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

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

【问题讨论】:

  • Shell 脚本并不是万能的。我只能在这里告诉你。
  • 是的。但它可以调用其他可以部分完成工作的程序......这个想法是我们可以连接两个独立的程序......
  • 找到一个 CLI 项目,它可以编写任何你想要的文件格式。这与任何 shell 关系不大,更不用说 bash。

标签: bash shell automation openoffice.org libreoffice


【解决方案1】:

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

所以。 让我们说:

  • 模板位于示例的图像im1.pngimg2.pngimg3.png旁边的/path/to/the/template.fodp
  • 第一张图片的名称是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"

我不是一个大程序员。因此,这些行中可能存在一些错误。但原理是有的。

它们是一些约束:

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

【讨论】:

  • 谢谢!这是一个老问题..会尝试让你知道。
猜你喜欢
  • 2013-03-05
  • 1970-01-01
  • 1970-01-01
  • 2021-07-23
  • 1970-01-01
  • 2022-08-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多