I have a few hundred image files. This consist of files of multiple type like 1.png 2.jpg 3.png and so on. I want to create a PDF from these images without changing the order of pages. The number in the image name must be used to preserve the order of pages.


2 Answers 2


Using imagemagick, you could use a script like that

TMP=`mktemp -d`
for img in `ls`; do
    convert "$img" "$TMP"/"$img".pdf

convert $TMP/*.pdf merged.pdf

EDIT: I saw now a similar response. The only thing that this script adds is merging all the files in only one pdf.

  • Actually I used pdfunite at the last line as convert is blurring the images
    – Sunny
    Nov 20, 2015 at 12:19

You could create a bash script:


for f in *.jpg; do
  convert ./"$f" ./"${f%.jpg}.pdf"

EDIT: Source - https://unix.stackexchange.com/questions/29869/converting-multiple-image-files-from-jpeg-to-pdf-format

  • OP said that there are multiple extensions like jpg and png, not only one. And you could just write that command in one line instead of creating a script file for it.
    – Byte Commander
    Nov 20, 2015 at 11:28
  • I missed that...I'll have to pay closer attention, apparently Nov 20, 2015 at 11:29

Not the answer you're looking for? Browse other questions tagged .