title: Merge multiple JPGs into single PDF in Linux
body: <p>I used the following command to convert and merge all the JPG files in a directory to a single PDF file:</p>
  <pre><code>convert *.jpg file.pdf
  </code></pre>
  <p>The files in the directory are numbered from <code>1.jpg</code> to <code>123.jpg</code>. The conversion went fine but after converting, the pages were all mixed up. I wanted the PDF to have pages from <code>1.jpg</code> to <code>123.jpg</code> in the same order as they are named. I tried it with the following command as well:</p>
  <pre><code>cd 1
  FILES=$( find . -type f -name &quot;*jpg&quot; | cut -d/ -f 2)
  mkdir temp &amp;&amp; cd temp
  for file in $FILES; do
      BASE=$(echo $file | sed 's/.jpg//g');
      convert ../$BASE.jpg $BASE.pdf;
      done &amp;&amp; 
  pdftk *pdf cat output ../1.pdf &amp;&amp;
  cd ..
  rm -rf temp
  </code></pre>
  <p>But still no luck. Operating system is Linux.</p>