Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merge multiple jpg into single pdf in Linux

I used the following command to convert and merge all the jpg files in a directory to a single pdf file.

convert *.jpg file.pdf 

The files in the directory are numbered from 1.jpg to 123.jpg. The convertion went fine but after converting the pages were all mixed up. I wanted the pdf to have pages from 1.jpg to 123.jpg in the same order as they are named. I tried with the following command as well:

cd 1  FILES=$( find . -type f -name "*jpg" | cut -d/ -f 2) mkdir temp && cd temp  for file in $FILES; do      BASE=$(echo $file | sed 's/.jpg//g');     convert ../$BASE.jpg $BASE.pdf;      done &&  pdftk *pdf cat output ../1.pdf &&  cd ..  rm -rf temp 

But still no luck. Operating platform Linux.

like image 557
Harikrishnan Avatar asked Nov 29 '12 03:11

Harikrishnan


People also ask

How do I combine multiple JPG into one PDF?

Simply visit the Acrobat Online website and upload the files you want to merge. Reorder the files however you like and then click Merge files. After that, just download the merged PDF. This will combine all the JPGs-turned-PDFs into a single PDF you can easily share or view.

How do I combine multiple PDF files into one in Linux?

Combine PDFs with the gs commandUse the -sDEVICE attribute to specify the output device or function. Use the -sOUTPUTFILE to specify the merged PDF file. Use the -dBATCH to specify the PDF files to combine in the order you want them to appear. The command above will output merged_file.

How do I combine multiple JPG files into one?

Open a browser in JPG free application web site and go to the Merger tool. Click inside the file drop area to upload JPG files or drag & drop a JPG files. Click the 'MERGE' button to start merging files. Instantly download, view or send merged file as an email.


1 Answers

Or just read the ls manual and see :

-v natural sort of (version) numbers within text

So, doing what we need in single command.

convert `ls -v *.jpg` foobar.pdf 

Have fun ;) F.

like image 80
Felix Defrance Avatar answered Oct 13 '22 04:10

Felix Defrance