Search code examples
macospdfterminalzshgnu-parallel

Splitting multiple PDF files using parallel and mutool


There is a command called mutool than enables splitting PDF files vertically with this invocation mutool poster -y 2. I would like to run it on every PDF file of a directory.

I tried parallel 'mutool poster -y 2' ::: *.pdf , though that doesn't work since I get only one PDF file. I would like to get each file processed, if possible.

How can I achieve that ? If it isn't possible using GNU parallel, is there another way ?


Solution

  • Give mutool a name for the output file, otherwise it will use the placeholder name out.pdf (which it overwrites):

    parallel 'mutool poster -y 2 {} {.}_out.pdf' ::: *.pdf
    

    Synopsis of mutool poster command: mutool poster [options] input.pdf [output.pdf]. After the input filename, the output filename can be given.

    parallel replaces the curly brackets with input, as described in the documentation:

    If command or the following arguments contain replacement strings (such as {}) every instance will be substituted with the input.

    Description of the two replacement forms used above (there are many others):

    {} Input line. This replacement string will be replaced by a full line read from the input source.

    {.} Input line without extension. This replacement string will be replaced by the input with the extension removed.