For easy concatenation of PDF information, the utility pdfunite is about so simple as it will get. It is without doubt one of the utilities that include the Poppler PDF rendering library and could be put in with brew set up poppler. Additionally it is included within the poppler-utils package deal in Debian and Ubuntu and the poppler package deal in ArchLinux and Fedora for those who’re utilizing Linux.
The utilization is
pdfunite file1.pdf file2.pdf file3.pdf mergedfile.pdf
To course of all information with the extension “pdf” within the present listing within the order of string numerical worth if there aren’t any whitespaces in any of the information:
pdfunite $(ls -v *.pdf) output.pdf
And if there are likely whitespaces within the filenames, it will get a little bit extra sophisticated, however this could work:
(ls -v *.pdf; echo output.pdf) | tr n | xargs -0 pdfunite
Rationalization:
lsinvokes thelsout of your$PATHignoring any aliases. This can be essential in case you’ve an aliasedlsthat reveals further info (like particular characters to indicate sure permissions). You can even simply use an absolute path to thelsexecutable, like/usr/bin/ls.ls -vkinds the information in keeping with (model) numbers inside textual contenttr nreplaces newlines with NULLs after every filexargs -0tells xargs to make use of the NULL character to separate arguments
As you may see, correct dealing with of issues like whitespace (and different particular characters) when piping instructions within the shell can get a little bit sophisticated. If you would like to learn extra, I like to recommend David Wheeler’s complete article.
