1

I'm basically downloading some images from a website using wget to then append them into a PDF file using the command line program "convert". But this last thing seems not to work.

I'm getting all the .jpg images and storing them into one folder with no problems, but when I try to merge them into the PDF file, it always reminds with the last appended image. I've read of the convert's -append argument, but it still won't work.

This is how my code looks like:

for file in *.jpg
do
    convert "${file}" -append "myfile.pdf"  

done

But as logical as it seems, myfile.pdf always ends up having only the last jpg appended image. I know that using convert like:

convert img1.jpg img2.jpg img3.jpg myfile.pdf

Would do the trick. But as I don't know how many images will I have in the download directory, I cannot hardcode the arguments, so I guess a loop for each image in that directory as I'm trying would be the best solution.

Does anybody know how to achieve my goal? Any help will be much appreciated.

Thanks in advance.

1

If all of your images are in the current directory, you can simply do this:

convert *.jpg myfile.pdf

which is the same as manually specifying all the images:

convert img1.jpg img2.jpg img3.jpg myfile.pdf
| improve this answer | |
  • Damn, you're right! The scrpit was originally a loop, so when I decided to convert all the images into a single pdf, I kept with the loop idea in mindo so I was trying the wrong way... Thank you so much! – Miquel Perez Sep 26 '16 at 20:55
  • Note that if there are more than 9 numbered images, the resulting page order may not be what you expect (due to lexical collation ordering of the filename glob). With zsh you could use the (n) modifier I think *.jpg(n). – steeldriver Sep 26 '16 at 23:32

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.