1

I want merge several pdf files into a single one. Found this great answer on SO, but there is a problem here. My pdfs are not in the same directory, so essentially I want to do a find call and pipe the output to gs, something like this:

find . -path "*_somedir/*" -name "some.pdf" -print0 | gs ...

I have checked the manual pages for gs but there is no information for null-terminated arguments, so I am not sure how to pass the arguments from find to gs. I assume if I skip the -print0 flag it will run the gs call after the first argument.

Any ideas? I am of course open to other ways to merge the pdfs but I'd like to avoid installing new packages since this is to be done on a community server.

  • Have you tried using xargs? Also there are pdf tools packages on various distros that do a great jobs of simply merging pdfs – bsd Sep 26 '16 at 9:56
3

One way to do it, assuming GNU find(1) and GNU xargs(1):

find /some/dir -type f -name '*.pdf' -print0 | \
    xargs -0 gs -q -dNOPAUSE -sDEVICE=pdfwrite -dBATCH -sOUTPUTFILE=out.pdf

However, PDFs are complicated beasts. Expect mixed results from this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.