Convert Many PNGs into one PDF incuding all files in Subdirectories in Order

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
InternetDirigible
Posts: 1
Joined: 2016-07-04T15:56:09-07:00
Authentication code: 1151

Convert Many PNGs into one PDF incuding all files in Subdirectories in Order

Post by InternetDirigible »

So I have this structure

Folder1/
/1.png
/2.png
.....
/20.png

Folder2/
/1.png
....
/12.png

...........

Folder10/
/1.png
....etc

I want to put ALL pngs from all of these subfolders into one pdf in the order they're stored in. There are a lot of files with the same names so I can't just flatten the directory without significant time manually renaming the files or else the files would get completely out of order. If I type:

convert *.png Combined.pdf

It ignores subdirectories. What can I do? I'm not an expert at imagemagick or CMD but I learn quickly.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert Many PNGs into one PDF incuding all files in Subdirectories in Order

Post by fmw42 »

Imagemagick does not traverse directories as far as I know. You have to control that via scripting, typically.

You should rename your images so that you use leading zeros, since they get sorted alphabetically in wildcard searches. You will likely need to write a loop over each directory or manually write images with paths to a string or text file in the directory order you want. That would make it easy to read the string or text file as a list of input files. Having leading zeros makes the list of files in your directories in the proper order already.

Please, always provide your IM version and platform when asking questions, since syntax may differ.

See viewtopic.php?f=1&t=9620
Post Reply