0% found this document useful (0 votes)
78 views3 pages

Command Line - Converting Hundreds of JPG To PDF Using Terminal - Ask Ubuntu

The document discusses converting multiple JPEG files into individual PDF files using the command line in Linux. It asks how to convert files like myJPG1.jpg to myPDF1.pdf. The responses provide solutions using ImageMagick's convert tool or the find and parallel commands to batch convert the JPEGs to sequentially numbered PDFs while avoiding quality loss.

Uploaded by

Caspicus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
0% found this document useful (0 votes)
78 views3 pages

Command Line - Converting Hundreds of JPG To PDF Using Terminal - Ask Ubuntu

The document discusses converting multiple JPEG files into individual PDF files using the command line in Linux. It asks how to convert files like myJPG1.jpg to myPDF1.pdf. The responses provide solutions using ImageMagick's convert tool or the find and parallel commands to batch convert the JPEGs to sequentially numbered PDFs while avoiding quality loss.

Uploaded by

Caspicus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
You are on page 1/ 3

3/21/2019 command line - Converting hundreds of jpg to PDF using Terminal - Ask Ubuntu

Ask Ubuntu is a question and answer site for Ubuntu users and
developers. Join them; it only takes a minute:

Sign up

Here's how it works:


Anybody can ask a question
Anybody can answer
The best answers are voted up and rise to the top

Converting hundreds of jpg to PDF using Terminal Ask Question

I know that the command convert


*.jpg myPdf1.pdf can convert
7 multiple JPEG files into a single PDF.

But I would like to convert multiple


JPEGs into multiple PDFs, for
example:
1
myJPG1.jpg → myPDF1.pdf
myJPG2.jpg → myPDF2.pdf
myJPG3.jpg → myPDF3.pdf

Is there any decent way to manage


something like that?

command-line format-conversion

edited May 23 '14 at 16:41


Oli ♦
223k 89 566 766

asked May 23 '14 at 16:11


Your Majesty
175 1 1 5

How would you order them? – jobin


May 23 '14 at 16:12

Well suppose they are called


myJPG1, myJPG2 and so on, and
you want to convert them to myPDF1,
myPDF2 and so on. – Your Majesty
May 23 '14 at 16:15

The question isn't clear, do you have


multiple jpgs or pdfs? You can convert
multiple jpgs to a single pdf using the
command you have used in your
question. – jobin May 23 '14 at 16:17
By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service.
It should be clearer now, I just want a
bunch of PDF's with names myPDF1
https://askubuntu.com/questions/471178/converting-hundreds-of-jpg-to-pdf-using-terminal 1/3
3/21/2019 command line - Converting hundreds of jpg to PDF using Terminal - Ask Ubuntu
bunch of PDF s with names myPDF1
myPDF2 and so on. But Your
suggestion, into a single PDF, also
sounds nice. Thanks. –
Your Majesty May 23 '14 at 16:24

2 Answers

My first instinct for batch processing


files is almost always find . It's
9 excellent if you need to build in any
sort of filtering (which you don't here)
but it's still a favourite. This will also
recurse into subdirectories unless
you tell it (with -maxdepth 1 or
other):

find -name '*.jpg' -exec conver


rename 's/\.jpg\.pdf$/.pdf/' *.

The find / convert statement will


output a load of .jpg.pdf files. The
second cleans this up.

Perhaps a slightly more elegant


approach in such a simple case:

for file in *.jpg ; do convert

This doesn't recurse and you don't


have to mess around cleaning up the
filenames.

And I almost forgot, ImageMagick


has a numerical output which might
fit your use-case perfectly. The
following will just stick a three-digit
identifier ( 000 , 001 , 002 , etc) on
the end of the "myPDF":

convert *.jpg myPDF%03d.pdf

Obviously if you're dealing with more


than a thousand entries, increase the
number. If you don't want it zero-
padded, remove the leading zero.

edited May 23 '14 at 16:45

answered May 23 '14 at 16:31


Oli ♦
223k 89 566 766

find -name '*.jpg' | parallel 'convert {}


{.}.pdf' – Yauhen Yakimovich Mar 9
'15 at 12:03
By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service.

https://askubuntu.com/questions/471178/converting-hundreds-of-jpg-to-pdf-using-terminal 2/3
3/21/2019 command line - Converting hundreds of jpg to PDF using Terminal - Ask Ubuntu

Unfortunately convert changes the


image before so to have minimal loss
1 of quality of the original jpg you
need to use img2pdf wich makes
the pdf with the original jpg so no
loss, I use this commands:

1) This to make a pdf file out of


every jpg image without loss of
either resolution or quality:

ls -1 ./*jpg | xargs -L1 -I {} i

2) Here you will have the *.pdf s as


*.jpg.pdf , so will do a little
renaming

mmv "*.jpg.pdf" "#1.pdf"

You need to have installed img2pdf


and mmv

sudo apt install img2pdf mmv

edited Feb 8 '18 at 9:52

answered Feb 8 '18 at 9:42


Eduard Florinescu
2,282 8 30 42

By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service.

https://askubuntu.com/questions/471178/converting-hundreds-of-jpg-to-pdf-using-terminal 3/3

You might also like