将PDF与文件名中的空格合并

时间:2020-07-06 17:34:54

标签: linux unix pdf pdftk

我的目录中有很多PDF,它们的文件名中都有空格。

file 1.pdf
file 2.pdf
file 3.pdf
# And so on

我在该目录中运行了该命令。

pdftk `ls -v` cat output combined-report.pdf

但是终端吐出了很多这样的错误。

Error: Unable to find file.
Error: Failed to open PDF file: 
   file
Error: Unable to find file.
Error: Failed to open PDF file: 
   1.pdf

如何在Arch Linux中使用pdftk或任何其他软件包来合并PDF?为了澄清,我想按ls -v

打印的顺序合并文件

2 个答案:

答案 0 :(得分:2)

在创建合并类似pdf的文件时只需使用通配符即可

pdftk *.pdf cat output newfile.pdf

否则,您可以使用类似以下的内容:

pdftk file\ 1.pdf file\ 2.pdf cat output newfile.pdf

答案 1 :(得分:1)

尝试一下:

find . -name 'file*.pdf' -print0 | sort -z -V | xargs -0 -I{} pdftk {} cat output combined-report.pdf

或者这个:

ls -v file*.pdf | xargs -d'\n' -I{} pdftk {} cat output combined-report.pdf

在第一行中,“-print0”,“-z”和“ -0”告诉相应的命令使用null作为定界符。用于排序的“ -V”参数指定“版本排序”,我认为它应该产生您想要的排序。通常,通过管道传递的参数将附加到xargs的末尾。 “ -I {}”指定占位符“ {}”,可用于将其置于命令中间。

第二行类似,除了它从“ ls”中获取参数,并使用换行符'\ n'作为分隔符。

注意:使用“ ls”存在潜在的问题。请参阅@ stephen-p发布的链接。

相关问题