batch-filecmdcommand-linecommand-line-argumentsimg2pdf

Use img2pdf in batch command line


I have been looking for some time for a solution to a "very simple" question. I created a batch file (under windows) which allows me to download a set of images. I would just like to merge these images into a PDF (image 1: page 1, image 2: page 2 etc ...). I am using (for shell) the excellent img2pdf package and it works great!

So under windows I do the same: I download (with python and pip) the package and I give it this command (exactly the same under shell):

img2pdf *.jpg -o FILE.pdf

Unfortunately it does not recognize the *.jpg (which stands for "all files with a .jpg extension").

I would like to point out that, of course, my files are in .jpg and that the package works perfectly because with one file (img2pdf 1.jpg -o FILE.pdf) it does the job.

How then to make him understand that?

Thank you in advance for your help !


Solution

  • It seems that img2pdf does not support wildcards, but it might support a list of files:

    @echo off
    setlocal EnableDelayedExpansion
    rem // Build a space-separated list of quoted file names:
    set "LIST=" & for %%I in ("*.jpg") do set "LIST=!LIST! "%%I""
    rem // Provide the built list as arguments to the tool:
    img2pdf !LIST! -o "FILE.pdf"
    endlocal