0

I currently have over 10K folders. Each folder has .png and .jpg images that need to be turned into .pdf files. Files are numerically in order already.

I am looking for speed. I can currently cd into each folder and run

img2pdf * -o out.pdf

And I get a perfectly created out.pdf in less than a second, even with several hundred images.

My end goal is to automate this in a shell script that can be invoked, so each folder is basically turned into a .pdf file with the filename the same as the old directory like so

Directory001/img001.jpg
             img002.jpg
             img003.jpg
OtherDirectory/img1.png
               img2.png
               img3.png

becomes

Directory001.pdf
OtherDirectory.pdf

while only use img2pdf to do this, as it is by far the fastest way create the pdfs. I have some simple bash experience, but only with simple one liners (like turning all directories to zips). I know this can be done, but have no idea where to begin.

0

To batch a command over a lot of files or directories, you often use find -exec like this :

find . -type d -exec "img2pdf" "{}"/* -o "{}".pdf ";"

this method is the most flexible, but in your case, you could as well use a simple loop :

for i in ./*/
   do img2pdf "$i"/* "$i.pdf"
done

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.