Home Downloads How to Quickly Convert JPG to PDF on Linux

How to Quickly Convert JPG to PDF on Linux

Converting JPG files to PDF on Linux can streamline document management and make sharing easier. This guide covers command-line and GUI methods to convert your images, ensuring a smooth process regardless of your preference or experience level.

by Arun Kumar
convert jpg to pdf in linux

This guide shows various methods, highlighting the simplicity of using the convert command in ImageMagick for quick conversions, the efficiency of batch processing, and the capability to compile multiple images into a single PDF document. We also introduce pdftk, catering to those seeking more advanced control over their PDF files, such as adjusting metadata and dictating document structure.

Why bother with the command line?

First off, you might wonder, “Why not just use an online converter?” Well, where’s the fun in that? Plus, using the command line offers a level of precision and efficiency that’s hard to beat. And let’s not forget about privacy concerns with online tools. So, let’s get our hands dirty with some terminal magic.

Converting JPG to PDF

Method 1: Using Imagemagick

Preparing your environment

Before we start, ensure you’re working on a Linux distribution like Ubuntu. It’s my go-to because of its user-friendly interface and vast repository of tools. For our purpose, we need to install ImageMagick, a powerful software suite that can create, edit, compose, or convert digital images in a wide variety of formats.

Open your terminal and type:

sudo apt-get update
sudo apt-get install imagemagick

This command updates your package lists and installs ImageMagick. Simple, right?

Convert a single JPG to PDF

Now, for the fun part. Say you have a meme in JPG format that you desperately want to convert to PDF. Here’s how you do it:

  1. Navigate to the directory containing your JPG file.
  2. Use the convert command from ImageMagick:
convert myMeme.jpg myMeme.pdf

Voilà! Check your directory, and you’ll find myMeme.pdf sitting there, probably feeling superior to its JPG counterpart.

Batch conversion

What if you have not one, but a whole folder of memes to convert? Fear not, for the command line is our mighty ally. Enter the following:

mogrify -format pdf *.jpg

This command converts all JPG files in the current directory to PDFs. Each file will retain its original name, which helps keep your meme collection organized.

Merging multiple JPGs into a single PDF

Sometimes, you might want to compile multiple images into a single PDF document. ImageMagick makes this a breeze:

convert *.jpg myCompiledMemes.pdf

This command takes all JPG files in the directory and merges them into a single PDF. How cool is that?

Method 2: Using pdftk for advanced PDF creation

First, we’ll need to install pdftk. On Ubuntu, you can do this by running:

sudo apt-get install pdftk

Once installed, pdftk offers a plethora of features, but let’s focus on creating a PDF from JPG images.

Convert and merge JPGs into a single PDF with pdftk

pdftk itself doesn’t convert JPG to PDF directly, but we can first use convert from ImageMagick to create individual PDF files from our JPGs and then merge them with pdftk. Here’s how:

  1. Convert all JPG images to individual PDFs as before:
convert *.jpg myImage%d.pdf

This command converts each JPG file in the directory to a PDF. The %d formatter in myImage%d.pdf generates a numeric sequence for each output file, ensuring a unique name for each PDF.

  1. Merge the PDF files into a single document:
pdftk myImage*.pdf cat output myCompiledAlbum.pdf

This command takes all PDF files starting with myImage and merges them into myCompiledAlbum.pdf. The cat operation is used for concatenating (merging) PDF files.

Why pdftk?

While the initial process might seem roundabout, pdftk shines in its ability to manipulate PDF files. You can merge PDFs, split them, encrypt or decrypt, rotate pages, and even fill out PDF forms from the command line. It’s a powerful tool for anyone looking to automate their PDF workflows.

Method 3: Using GIMP for JPG to PDF Conversion (GUI way)

GIMP (GNU Image Manipulation Program) is a free and open-source image editor available for Linux, Windows, and macOS. It’s highly versatile, allowing users to perform detailed image editing, create artwork from scratch, and, yes, convert images to different formats, including PDF.

Installing GIMP

If GIMP is not already installed on your system, you can easily install it from the Ubuntu Software Center or via the terminal. To install GIMP using the terminal, open it and type the following command:

sudo apt-get install gimp

This command downloads and installs the latest version of GIMP from the official repositories.

Converting a JPG to PDF

  1. Open GIMP: Start by opening GIMP. You can find it in your applications menu or launch it from the terminal by typing gimp.
  2. Open the JPG File: Click on File in the menu bar, then Open, and select the JPG file you want to convert.
  3. Export as PDF: Once your image is open, click on File again, then hover over Export As. In the export window, change the file extension of your image to .pdf. For example, if your image is named myImage.jpg, you would change it to myImage.pdf. Click Export.
  4. Adjust PDF Settings: A dialog will appear with PDF export options, such as applying compression or including the layers as separate pages. Adjust these settings as needed, then click Export.

And that’s it! Your JPG file is now saved as a PDF document.

Conclusion

As we wrap up this journey through converting JPGs to PDFs on Linux, it’s clear that the process is not just about achieving the end result but also about embracing the ethos of Linux. The command line, with tools like ImageMagick and pdftk, offers a playground for efficiency, customization, and control, transforming what might seem like a simple task into a craft.

You may also like

1 comment

Pelayo April 3, 2024 - 6:19 AM

The most comfortable thing, for me, is to use SCRIBUS. Import all the graphic files and generate a PDF to my liking… It allows you many options such as scaling, creating collages or making multipage files.

Reply

Leave a Comment

fl_logo_v3_footer

ENHANCE YOUR LINUX EXPERIENCE.



FOSS Linux is a leading resource for Linux enthusiasts and professionals alike. With a focus on providing the best Linux tutorials, open-source apps, news, and reviews written by team of expert authors. FOSS Linux is the go-to source for all things Linux.

Whether you’re a beginner or an experienced user, FOSS Linux has something for everyone.

Follow Us

Subscribe

©2016-2023 FOSS LINUX

A PART OF VIBRANT LEAF MEDIA COMPANY.

ALL RIGHTS RESERVED.

“Linux” is the registered trademark by Linus Torvalds in the U.S. and other countries.