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.

Subscribe to Newsletter!
Get notified when new articles are published!
We promise to never share your email!
icon

Author: KGIII

Retired mathematician, residing in the mountains of Maine. I may be old and wise, but I am not infallible. Please point out any errors. And, as always, thanks again for reading.

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe To Our Newsletter
Get notified when new articles are published! It's free and I won't send you any spam.
Linux Tips
Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.