up

Convert jpeg files to PDF under Linux

How to convert jpg files to one PDF?

Requirements:

  • Linux

    Ubuntu is my favorite. But you can use any other distribution.

  • ImageMagick
    Type the follow line to Ubuntu commmand prompt for intall ImageMagick:
    sudo apt-get install imagemagick

Convert from jpegs to PDF:

  • Go to the work directory (directory of jpegs):
    cd work/directory/path
  • Convert the JPG files to PDF:
    convert *.jpg foo.pdf

So easy, not?

Leave a comment if you can or can't convert your files?

Have you same problem in Windows? Download the PDFCreator. PDFCreator is a free tool to create PDF files from nearly any Windows application that is able to print. (Not just JPG)

Another solution in Linux:

Any KDE application can print in PDF file (same method as PDFCreator). Select JPG-s and print in PDF.

Blog categories:  Linux

Comments

Works perfectly. Really sweet. Thanks.

Thanks a lot. It really worked suberb.

Just what I needed. Thanks!

Thank you, it works!!!
--> Mandriva 2008 One spring

Add the following lines to your KDE file:

vi .kde/share/apps/konqueror/servicemenus/PDF_merge_images_to_pdf.desktop

[Desktop Entry]
ServiceTypes=image/*
Actions=setAsPdf

[Desktop Action setAsPdf]
Name=Convertir a PDF
Icon=pdf
Exec=convert %U foo.pdf

This doesn't work for me with the wild card, if I do convert *.jpg foo.pdf, I get "can't find *.jpg" I'm using ubuntu.

thanks
mbs

I got the same message first try. Remember - case sensitive so try *.JPG

It works...great. I was in the wrong directory the first time.

doesn't work for me, says it fails to find the file/directory...
i m doing something wrong, am i?

Hello,

Check your filenames. All file and directory name is case sensitive in linux. Check your command and modify it from *.jpg to *.JPG or something other correct extension.

thanks. it works the way I expected. :D

I tried to run this on 40 jpeg pages, and ran out of memory, had to add another 500MB of swap,
most of the images were at 300 dpi, vmsize went past 2.2GB

Allen

Yes, you need to add more swap if you haven't got enough memory. The convertion will be slower with swap, but convert process does not ran out of memory.

Thx your comment.

If there are text (as images) in jpeg does ImageMagick convert those to characters?

No, it doesn't convert those to characters.

If you want to convert single file:
convert 000.jpg 000.pdf

But if you want to convert multiple jpgs to one PDF you have to add -adjoin param:
convert *.jpg -adjoin 000.pdf

It works on mine Ubuntu and it's what manual says about converting few images into multiimage PDF.

I tried to run this on 40 jpeg pages, and ran out of memory, had to add another 500MB of swap,
most of the images were at 300 dpi, vmsize went past 2.2GB

Converting more than a few images can be a little tricky using only the command line. To batch convert them, use F-Spot.

1. Open F-Spot.
2. Add the images you want to convert, they must be in the order you want them.
3. Click print, and select "Print to file"

Your output will be the PDF file.

Or you could simply do this: for x in *.jpg; do convert $x `basename $x jpg`pdf; done

first, let us change the name of the jpgs to pdf:
prename 's/\.jpg$/\.pdf/' *.jpg
then, join them with pdfjoin:
pdfjoin *.pdf

Done :)

I'm new in linux. I've tried to convert *.jpg files into pdf and it worked...

These command convert *.JPG wathever.pdf works perfectly!!
Thanxxx!!!

Thanks a lot. Everything works fine!

Hi Thomas,

First of all thank you very much for mentioning about this tool.

I installed it and converted a bunch of files. All went smooth.

But the size of the pdf files generated were huge. This tool has a "compress" option but I don't know what value to pass.

So, I tried the suggestion (given in one of the comments) to use F-Spot and it worked sweetly.

And I managed to add 10 jpg files to F-Spot and select them all, click print, and chose the option to print to a pdf file.

Done. My jpg files were converted and that too with much less size.

Thanks anyway for everyone who gave your valuable thoughts.

Thanks a lot.
It worked like magic.

That is awesome!
Thank you mate!

Yes, this is a goal.
Thahks!

Just magic. 'Have been working on Linux (Xubuntu) for over 2 years now, no looking back...

Thank you so much for sharing!

Hi
I tried that with the command line but every time my pdf is corrupt or damaged. If i convert one jpg file is ok if i convert multiple jpgs to a pdf file it gives me the damaged pdf file.

could you send me a replay to my email?

best regards
Sani

I should mention that the pdfjam solution is far more efficient than imagemagick, it seems. The former took my 69MB of files and gave me a 71MB PDF, while the latter gave me a 445MB (!) PDF.

Doesn't work for me. It says "segmentation error" after a long while... Is there a limit for the number of pictures to put ?

Cause I tried that version & the command is hung there.

Thank you so much!

Simply amazing!!

That's fantastic! I knew how to print to pdf using print menu in the GNOME Image viewer, but it adds nasty white margins and a very large file size. This method doesn't have such drawbacks. Thanks! :)

Nice! if images have different sizes, can i tell imagemagick to convert resize them on the fly? something like
convert *jpeg -page 1400X1600 filename.pdf ?

Nice:)

Example: four DIN A4 sized 150 dpi jpeg-files (each about 330 kB on disk) resulted in a 23 MB PDF file without compression. Using the command:

convert -compress jpeg *.jpg output.pdf

created a PDF with reasonable 1.3 MB instead.

This really worked for me just fine :).

Long live imagemagick !!!

I need to convert PDF to JPG, my PDF has form fields (Textbox, dropdowns) on it and this conversion produces junk image which says I need to upgrade my PDF version to read it. I have a latest PDF reader. Have the same problem when I use pdftk to merge this form fields PDF with other PDFs, all other PDFs gets merged but the one with controls shows the same error message - need to upgrade PDF version.
Any help would be greatly appreciated. Thanks !

Thanks!

It's really magic.

Thank you :)

convert -destiny 300 (or 600, 1200.....) *.jpg foo.pdf - quality of convertation
convert -scale 2000x1000 (or......) *.jpg foo.pdf exact resolution

Add new comment