1

使用libreoffice批量转换文件和打印

 3 years ago
source link: https://www.lujun9972.win/blog/2018/07/02/%E4%BD%BF%E7%94%A8libreoffice%E6%89%B9%E9%87%8F%E8%BD%AC%E6%8D%A2%E6%96%87%E4%BB%B6%E5%92%8C%E6%89%93%E5%8D%B0/index.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

使用libreoffice批量转换文件和打印

与 Microsoft Office 很不一样的是,LibreOffice 居然提供了 CLI 让你可以在 shell 中使用。

批量转换文件格式

比如,我们可以使用 --convert-to 参数来实现文档的批量转换。 它的语法是

libreoffice --convert-to $OutputFileExtension [--outdir $output_dir]

$OutputFileExtension输出文件的后缀,指定了要将文档转换成哪种格式 --outdir $output_dir输出目录,指明了输出文件要存在哪个目录下,若没有指定则为当前目录

比如,我要把所有的 .docx 文件都转换成 pdf, 那么可以这么做

libreoffice --convert-to pdf *.docx

通过 -p 参数,我们还能实现多个文档的批量打印

libreoffice -p *.docx

会将当前目录下所有的docx都通过默认的打印机打印出来。

若需要指定其他打印机怎么办呢?也有办法, --pt 参数可以让你指定要打印的打印机

libreoffice --pt ${Printername} *.docx

终端显示文档文本内容

更变态的是,libreoffice 还能将文档的文本内容在终端上显示出来,这个功能可以跟 grep 连用,来搜索文档中的指定内容。

比如下面命令可以查找所有docx文档中包含emacs的内容。

libreoffice --cat *.docx |grep -i emacs

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK