0

I'm still learning the command line, and I'm having trouble piping a list of files into graphicsmagick for conversion to pdf:

find . -type f | sort | gm convert file.pdf

This gives the error: gm convert: Request did not return an image.

Can I do this without resorting to more complicated methods?

user2089518
  • 401
  • 4
  • 9

2 Answers2

2

This is an old question, but I found it looking for a solution to the same problem and never really found a complete answer. I came up with a simple(-ish) way of doing it myself:

gm convert $(find . -type f -printf '%p\0' | sort -z | sed 's/\x00/ /g') file.pdf

It won't work if there are spaces or new lines in any of the original files' paths, though.

This method has to execute convert once for every input file. It takes much (much much) longer, especially if there are a large number of original images, but it won't get tripped up by file names:

find . -type f -printf '%p\0' | sort -z | xargs -0 -I {} gm convert -adjoin file.pdf {} file.pdf
Cameron
  • 38
0

From the manual,

convert [ options ... ] input_file output_file

So you need to specify your files...

for i in `find . -type f | sort`
do
  gm convert "$i" "$i".pdf
done
  • This looks like it will convert each individual file into a pdf. What I need is to convert a group of files into a single pdf. Will this do that? – user2089518 Apr 13 '14 at 03:43
  • No. You'll need to use some other mechanism to do that. One program that can combine multiple images into a multi-page PDF is xsane. – Elliott Frisch Apr 13 '14 at 03:47