Need to combine multiple JPEG images into a single PDF document on your Ubuntu system? The command line offers a fast and efficient way to achieve this. This article explores several methods, focusing on tools readily available in Ubuntu and how to use them effectively.
While graphical tools exist, the command line provides several advantages:
convert
CommandImageMagick is a powerful image manipulation tool available on most Linux distributions. Its convert
command is perfect for this task.
Installation: If you don't have ImageMagick installed, use the following command:
sudo apt-get install imagemagick
Basic Conversion: To convert all JPEG files in the current directory to a single PDF, use:
convert *.jpg pictures.pdf
This command concatenates all .jpg
files into a PDF named pictures.pdf
.
Ordering Files: The order of images in the PDF will follow the alphabetical order of the filenames. For correct ordering, especially with numbered files, name them with leading zeros (e.g., image01.jpg
, image02.jpg
, ..., image10.jpg
).
Auto-Orient Images: To automatically rotate images based on their EXIF data, use the -auto-orient
option:
convert *.jpg -auto-orient pictures.pdf
img2pdf
for Lossless ConversionFor minimal quality loss during conversion, img2pdf
is an excellent choice. This method preserves the original JPEG data within the PDF.
Installation: Install img2pdf
using:
sudo apt-get install img2pdf
Conversion: The simplest command is:
img2pdf *.jpg --output combined.pdf
This creates combined.pdf
from all JPEG files in the directory.
OCR (Optional): To add an OCRed text layer for searchable PDFs, use ocrmypdf
:
ocrmypdf combined.pdf combined_ocr.pdf
Install ocrmypdf
if you don't have it: sudo apt-get install ocrmypdf
.
pdfjam
pdfjam
is another efficient tool, especially when working with LaTeX.
Installation: Install pdfjam
using:
sudo apt install pdfjam
Alternatively, it might come with texlive-extra-utils
:
sudo apt install texlive-extra-utils
Conversion: To create an A4-sized PDF from all JPEG files:
pdfjam --a4paper *.jpg
This creates a PDF named yourfiles-pdfjam.pdf
. Use the --outfile
option to specify a different output name:
pdfjam --a4paper *.jpg --outfile combined.pdf
Handling Filenames with Spaces: If your filenames contain spaces, use quotes around the filename variables in your commands.
Memory Issues: If you encounter memory issues with a large number of files, consider converting images in smaller batches or using tools like img2pdf
which process files one by one.
Image Compression: Be mindful of compression options. Using the +compress
option in convert
disables compression, leading to significantly larger PDF files. Omit compression options to maintain the original JPEG compression.
Alternative Tools: LibreOffice Writer can also be used by opening the images and exporting them as a PDF. You can also find various online converter websites that offer this functionality.
By utilizing these command-line methods, you can efficiently convert directories of JPEG files into single PDF documents on your Ubuntu system. Choose the method that best suits your needs, whether it's speed, quality preservation, or advanced options like OCR.