Turn A JPG Into A PDF

Today’s article is an article that few folks are going to need, but those folks who do need to turn a JPG into a PDF will be happy with it. If you want to do that, this article will help you with that task.

There are times when you want to need to share an image but the people you’re working with expect a PDF. This happens if you’re sending stuff off to be printed and things like that. They only accept PDFs and all you’ve got is a JPG. 

Well, it’s easy to turn a JPG into a PDF.

JPG, or JPEG, stands for Joint Photographic Experts Group and has been a standard since 1992. Obviously, it is an image format. According to Wikipedia, JPG “… was largely responsible for the proliferation of digital images.” That sounds reasonable to me.

I’ve covered a lot of PDF stuff lately. Can you tell where I am in my notes? PDF stands for Portable Document Format and is useful when you want to print something exactly as you see it. That’s why print houses use PDFs a great deal.

I’m sure this isn’t something everyone is going to need to do. That’s fine. Not all of my articles need to apply to everyone. I’m also hoping to use this opportunity to expose you to one of the more powerful Linux applications.

ImageMagick:

The tool we’re using is a complicated tool known as ImageMagick. Once installed, you should check the man page. We’ll be limiting those options to just a couple, but manipulating images in the Linux terminal is usually done with ImageMagick. It’s a versatile application.

If you do check the man page, you’ll learn that ImageMagick is described like so:

ImageMagick – is a free software suite for the creation, modification and display of bitmap images.

That’s not a very good description, because ImageMagick does a lot more than they describe, including formats other than the BMP format. It’s a potent tool that manipulates images directly in the Linux terminal. You’ll also find that ImageMagick is a great asset when dealing with large numbers of files.

Once you’ve installed ImageMagick, you have access to the convert command. You can’t have one without the other and you only need to install ImageMagick to have access to both. If you check the man page for convert, you’ll see that it’s the correct tool for the job.

convert – convert between image formats as well as resize an image, blur, crop, despeckle, dither, draw on, flip, join, re-sample, and much more.

If you’re observant:

The convert-im6.q16 program is a member of the ImageMagick-ims6.q16(1) suite of tools.

That’s why we have to install ImageMagick to get access to the convert command. There’s a lot to ImageMagick.

So, teach you one way to turn a JPG into a PDF…

Turn A JPG Into A PDF:

As mentioned above, you need a terminal to use ImageMagick. You don’t need a terminal to install ImageMagick, you can do that in a GUI. However, I’ll share how to install ImageMagick from the terminal. You can usually open a terminal by pressing CTRL + ALT + T on your keyboard.

With your terminal open, let’s get started:

Installing ImageMagick:

ImageMagick is not only a massively capable application, it is also widely available. You should find ImageMagick available in your default repositories. If it’s not in your default repositories, you can always compile it from the source. I’ll share how to install ImageMagick in the most popular distros:

Debian/Ubuntu/etc:

Arch/Manjaro/etc:

RHEL/CentOS/etc:

You can also install ImageMagick from source:

Turning A JPG Into a PDF:

Keep your terminal open and navigate to the folder where you’ve stored the image files. Specifically, use cd to navigate to the directory that contains those images you want to turn into PDF files.

With that done, you’re only really interested in the convert flag. You won’t be invoking the imagemagick command itself. You’ll be using the convert aspect of ImageMagick.

If you want to turn a JPG into a PDF, the syntax is quite simple:

DO NOT TRY THIS YET!

An example of that command would be:

I mean, you could try it – but it’s not going to necessarily work.

If you try the above command, you’ll likely get this error:

convert-im6.q16: attempt to perform an operation not allowed by the security policy `PDF’ @ error/constitute.c/IsCoderAuthorized/421

So, we need to edit the ImageMagic’s policy.xml file. It’s a simple edit and will only take you a few minutes. I’m going to assume that you have access to Nano, but you can use any terminal text editor you want.

First, open policy.xml for editing:

Find this line:

And edit it to match this line:

Now you need to save it. To save the new policy.xml with Nano, press CTRL + X, then Y, and then ENTER. That should save the file with the same filename and extension.

That’s all you need to edit. Now you can try this command!

Now you can turn a JPG to PDF easily in the Linux terminal with the convert command as provided by ImageMagick. Pretty complicated? I suppose so, but you only need to make that edit once and you’re good to go. 

Now that you’re done with that and are happily converting JPGs to PDFs in your spare time…

Well, it gets a little more complicated.

You might find that this command produces sideways images. If that’s the case, you’ll want to use the -auto-orient flag.

I swear, that’s the last thing you should have to tweak. In my experience, you don’t need the -auto-orient flag but it’s good to know that it exists. You might consider using it by default, just to ensure things go smoothly.

Oh, one more thing…

Let’s say you have a bunch of images in a directory and you want to turn all of those .jpg images into a .pdf en masse, you can do that! The convert command supports an asterisk (wildcard). That looks like this:

That’ll happily convert all the files ending with .jpg into a single .pdf file for you to store or share with others (such as a printing company). It’s pretty easy once you know the tricks and have edited the correct file.

BONUS:

While I only say ‘JPG’ in this article, you can also use this same command with  PNG files. The command is almost the same, you just need to specify a .png file instead of operating on a .jpg file. Like so:

That will happily perform the same operation on the .png file, just like it did with the .jpg file. The only reason it’s not mentioned previously is because it would have made the titles and headings look awkward.

So, if you need to turn a PNG into a PDF, you now know how. If you wanted to turn a JPG into a PDF, you now know how. Congratulations! You’ve learned a little about ImageMagick.

Closure:

I’ve been meaning to write this article for some time. It was just too long and I didn’t quite know how to make it simple. I finally bit the bullet and wrote it. If all goes well, this will be simple enough for anyone to follow. There are a few challenges along the way that may make this difficult for a novice, but the directions are hopefully clear enough for anyone to follow.

I know that I’ve needed to turn a JPG into a PDF. I’ve had to do so specifically for the reason mentioned above. If you ship something off to a professional printer, they may want the format to be PDF.

They do that for good reason. What you see in a PDF should be exactly what you see when you print the file. It’s a pretty handy file format and the standard is open source.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

How To: Convert JPG to PNG

In today’s article, we’re going to learn how to convert JPG to PNG image files. It’s a pretty easy process. In fact, the second part of the article should be fairly brief. Read on to learn more!

I should also mention that we’ll be learning how to convert JPG to PNG in the terminal. There are all sorts of GUI ways to do so, from individually converting files to batch conversions. Well, you can do all that in the terminal and this article will show you how.

Why PNG? Well, it supports lossless compression. PNG also supports transparency. PNG also looks better at higher resolutions, as it is able to display more details. Additionally, PNG not only supports lossless compression, it supports compression better – so you needn’t transfer larger files if you have no reason to do so. Plus, PNG is one of the better formats if  you’re going to do things like share the images online.

So, there are a number of reasons why you’d want to convert JPG to PNG. Fortunately, as I mentioned above, it’s really not all that difficult. You have tools to do this right in your default repositories, assuming you’re using a mainstream distro.

Without further ado…

Convert JPG to PNG:

As we’ll be converting in the terminal, you will have to have an open terminal. To do that, just press CTRL + ALT + T and your default terminal should open. See? We’re off to a good start.

Now, the tool we’ll be using is ‘ImageMagick’ and it’s available to install via  your normal channels. If you were using a distro that uses apt (Debian/Ubuntu/Mint/etc) then it’s trivial to install with:

Otherwise, install it with your default package manager tools. (You just might have installed when we covered how to resize images with ImageMagick. If not, now’s a good time to install it and then read that article!)

So, next you’ll either want to use the /path/to/directory where your JPG files are,  or just navigate to the directory where you’ve stored them (the easiest path), and you can convert them all with just one command:

Congratulations, in just that one command you’ll have converted all the JPG to PNG files. Feel the power of Linux! You’ll retain the originals, just in case something goes awry. If you’re happy with the results, you can always delete the originals with any one of a number of commands.

So, what if you just want to convert one JPG to PNG? Well, that’s easy:

See? I told you it was easy. While there’s a whole lot of complexity with ImageMagick, it can be quite simple to use for some very generic day-to-day tasks. Of couse, man imagemagick is always an option to learn more.

Closure:

Yup… It’s really not all that hard to convert JPG to PNG files with ImageMagick. If it’s a large number of files, it could be a bit for you to convert them all, but let it do its thing and it won’t take too long on a modern computer. If you only need to convert one image, that’s fine too.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Linux Tips
Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.