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: Remove A PDF Password

This will be a straightforward task for anyone who would like to know how to remove a PDF password in the Linux terminal. If you deal with a lot of PDFs and want to remove the password, it’s a fairly easy task. Read this to learn more!

As mentioned before, PDF stands for Portable Document Format. This is a ratified ISO standard (ISO 32000) and is an open standard. You can see a bit about the PDF standard here on the ISO website. However, unless you have a subscription, they’ll want you to pay for this. I am not paying for this as I do not need to know the specifics.

Many people think that it’s proprietary because it comes from Adobe, but it’s an open standard and there’s a bunch of software available to manipulate and create PDF files. The standard has been open since 2008 which explains the myriad choices for editors.

Seeing as you’re here, you might as well read this interesting Wikipedia article:

History of PDF

PDFs can come with different levels of security. They can have passwords that lock the ability to edit the file and they can have passwords that you need just to open the PDF file.

This article assumes that you know the password! The exercise in this article only applies if you already know the password. I did write an article about cracking a PDF password, but that can take a long time.

How To: Crack A PDF Password

So then, which tools are we going to use?

poppler:

We’ll be installing a meta package known as poppler. This may come pre-installed on your system, or you may need to install poppler manually. We’ll go over installation instructions for a variety of distros, as it’s widely packaged and available in the various distro’s default repositories.

You’ll find that poppler is a meta package. That is, it contains other packages. In this case, poppler contains other applications that are used to manipulate PDF files. There’s no such thing as man poppler for example. It’s just the package name for a package that contains other packages. (That’s a meta-package.)

If you dig into it, you’ll find that poppler contains applications like pdffonts and pdfimages. At this point, we’ve previously covered pdftotext. This time around, we’ll be using pdftops. We’ve not yet used this tool in other articles, so now is as good a time as any to learn about it.

pdftops:

This pdftop application is mostly intended to turn PDF files into PS (PostScript) files but has other uses. Sort of like how a medication can be prescribed off-label, so too can you use this tool for other things. This time around, we’ll be using the pdftops to remove a PDF password.

If you had poppler installed already and checked the man page, you’d see something that should be close to this:

pdftops – Portable Document Format (PDF) to PostScript converter (version 3.03)

We’ll be skipping that whole bit about converting it to a file formatted for PostScript. That’s not necessary for our goal – removing a password from a PDF-formatted document.

But, this tool contains the necessary commands to remove a PDF password. If the file has multiple passwords it will remove the password specified. Your best bet is to remove the password that enables editing. This will also unlock the PDF for viewing purposes.

Remove A PDF Password:

If you want to remove a PDF password, you can use a GUI tool and then choose the ‘export’ option – or maybe the ‘save as’ option. In our case, and as mentioned above, we’ll be using the terminal to remove a PDF password. If you don’t know how to open a terminal, that’s usually accomplished by finding the application in your menu or by pressing CTRL + ALT + T on your keyboard.

With your terminal now open, we need to install the poppler meta package. I’ll include the commands as I understand them but you may need to doublecheck my work. Depending on your package manager, try the following:

Debian/Ubuntu/etc:

RHEL/CentOS/etc:

OpenSUSE/SUSE/etc:

Gentoo:

Arch/Manjaro/etc:

One of those should work with all the major distros out there. If you’re using an obscure distro with an obscure package manager, the poppler utilities should be available to you. You’ll just need to edit your installation command to match your package manager.

Also, if you do need to do that, please let me know. If you let me know, I can include the command in the article, thereby making the article more useful to more people. One of my primary goals is to be useful. It’s good to be useful to more people.

On to the meat of the article:

Removing A PDF Password:

As you’ve already got your terminal open, you might as well keep that terminal open. The application we’re using is pdftops and you can use the following command to ensure that pdftops is properly installed:

The output should look similar to this:

While you’re there, you can check the man page. There are many options available for the pdftops command and you can check them with this command:

Now that we’ve checked the man page, we’re looking for the -upw flag. That’s the flag that’s going to do the heavy lifting and the man page describes it like so:

Specify the user password for the PDF file.

So, you can see where this is going…

The syntax is quite simple. It will look like this:

If you want to specify the owner password, you use the -opw flag. You can pick which password it is that you’re using and the output file will not have that password. Specifying this flag will remove all restrictions, of course.

Let’s try to give you an example…

I wrote an article about how to crack a PDF password and I included a link. For the sake of clarity, you can now download that PDF file.

Example PDF File

The password for that file is ‘abab’ and not one of you took the time to crack it. I made it nice and simple for you, but not one of you took the time to crack the password.

Still, we can use that in our example:

Rather than converting to PostScript, we are just opening and unlocking the file. At that point, we’re redirecting that unlocked content to a new PDF file. In the process, we’re stripping the existing password, meaning you can easily access the file in the future – even if you’ve long since forgotten the password.

Closure:

I’m not sure how often you work with PDF files, but this might be something you can use. You don’t need to remember complex passwords unless you want to. Very few people are interested in maintaining a mental list of all the passwords they use.

It’s not like there’s a password manager for PDF files (as far as I know). You’re stuck referencing the original place the password was shared or keeping some sort of list. Well, you do have another choice. You can learn how to remove a PDF password in the Linux terminal and be done with it. It’s up to you.

Anyhow, I figured this would make a good article. I don’t mention PDFs often and don’t write many articles on the PDF subject. There have been a few of them but there’s always more to cover. Today we just covered how to remove a PDF password. Maybe we’ll cover something else in the next article – but I’m more likely to skip a few articles so that it’s not just PDF content for a week.

Thanks for reading! If you want to help, or if the site has helped you, you can donateregister to helpwrite 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.

Seeing as you’re here, why not visit our friends at Blunix?

Here’s why you might just want to visit Blunix:

“Blunix GmbH offers Debian and Ubuntu focussed Linux Emergency Support 24/7, Project-based Linux Consulting, FOSS-based Managed Hosting on your company IaaS provider account as well as custom Training and Workshops. We prioritize fair business partnerships and employee quality of life over profit. We focus on reasonable security by default and encourage your employees and developers to keep things secure enough to avoid 99% of security issues with automated attack vectors. We focus exclusively on this and do partner with other companies to refer customers that do not fit exactly what we do, or where we require additional help (for example we have a security-focused company that we partner with for higher risk factor hosting setups).”

Click to visit Blunix GmbH

Turn PDF Into Text

Today’s exercise is simple, though it will rely on the terminal because we’re just going to turn PDF into text. This isn’t something complicated and it’s fairly effective. It’s also an exercise anyone can follow along with. So, if you want to turn PDF into text, read this article!

I’m sure this works in multiple distros, but I only have instructions for a few in my notes. Most everyone should be able to follow along with this article and turn PDF into text. You’ll see…

While I’m sure everyone is familiar with PDF, I’ll explain…

PDF stands for Portable Document Format and is one of many standards for documents. Specifically, it’s ISO 32000 and is a file format brought to use by Adobe. Adobe is a proprietary product but the standard is open, meaning you have your choice of PDF readers, editors, and creators.

On the other hand, PDF may not be as easily parsed as other file formats. You may also just want to extract some text from a PDF or turn it into something more information-dense, sans pictures and fluffy formatting. There are any number of reasons why you might want to turn PDF to text and it’s a simple operation that’s going to give you ‘acceptable’ results most of the time.

The tool we’ll be using…

pdftotext:

We’ll use a tool known as ‘pdftotext’ which does as its name implies. It’s a tool that lets you turn PDF into text, so from .pdf to .txt is the goal. Like many Linux tools, this is a terminal-based operation.

You can check to see if pdftotext is already installed with this command:

If the output matches this, you can skip the installation step:

If you want, you can check the man page and see that it is indeed the correct tool for the job if your job is to turn PDF into text. That’s this command:

That command will show you that the description is indeed what we want to accomplish in today’s article. That description is basically:

pdftotext – Portable Document Format (PDF) to text converter

(It may also tell you the version in that section, which is odd but is what it is.)

So, you can see that pdftotext is the correct tool for the job when you want to…

Turn PDF Into Text:

As I mentioned in the intro, if you want to turn PDF into text one of the ways to do so will require using the terminal. There are all sorts of GUI tools you can use to do this very same job, but we’ll do this in the terminal. So, you can usually get away with pressing CTRL + ALT + T to open your default terminal emulator. Otherwise, check your application menu and you’ll find a terminal option in there.

With your terminal open, we first will install a meta package so that we can use pdftotext to turn PDF into text. That application is ‘poppler’. You can pick from the following to match your package manager to install this.

Debian/Ubuntu/etc:

Arch/Manjaro/etc:

RHEL/Fedora/etc:

The poppler package contains pdftotext which is the tool we’re after in our quest to turn PDF into text. It’s a noble quest!

Now, the syntax is quite simple:

That will create a <file_name>.txt file in the same directory.

Now, if you checked the man page above, you’d see that there’s not a whole lot to this application. You can largely ignore all the options (and we will), though there aren’t that many.

The two options we are most interested in would be about just converting single pages into text. For that, you want the -f (first page) and -l last page flags. They do exactly what you’d expect and the syntax is as follows:

I’ll give you an example…

Let’s say you want to print pages 1 through 3. The syntax would be:

Sometimes this whole pdftotext thing doesn’t do a great job. If the PDF file is formatted in a fancy manner, it may just not come out in text all that well. Fortunately, PDF is an open standard and you can help it along with the -layout flag. 

The -layout flag is described like this:

Maintain (as best as possible) the original physical layout of the text. The default is to ´undo’ physical layout (columns, hyphenation, etc.) and output the text in reading order.

So, that flag will do its best to turn the layout into what it was in the original PDF. This is a handy flag for when the output isn’t usable. It’s possible to retain columns, advanced formatting, and all of that stuff, meaning the text file output is more useful. You won’t always need this option, but it can come in handy. You can safely ignore the remainder of the man page for the vast majority of what folks are going to do with this command.

That’s pretty much all you need to know about the pdftotext application. It does what you think it’d do. It’s the tool you use to turn PDF into text, just like it says on the tin! Pretty handy!

Closure:

So, that’s an article… 

If you’ve ever wanted to turn PDF into text, you now know how. You can use this to make a PDF easier to parse, easier to read, etc. It’s up to you how you use pdftotext. You now have the knowledge! You now have the power! Indeed, you have life by the horns. (Which is a rather silly place to grab onto.)

Man, this is a lot of articles… At this point, it’s almost habitual. Technically, I have published something every other day – for a long time. A couple of those articles weren’t really articles. They were placeholders because Mother Nature is a fickle beast and I live in a very remote location. We had a few major (deadly even) storms that took out our infrastructure. I think I can be forgiven for that – and I did upload articles saying that there’d be no article. 

The site has come a long way…

I haven’t done a meta article in a while…

Seriously, without you (my readers) I’d have never kept going this long. It’s obviously not a money-making operation, but it is an educational operation. That’s more important than money.

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: Crack A PDF Password

I don’t know how handy today’s article is going to be in reality but it’s sort of possible to crack a PDF password. Once you read the article, you’ll see why I said “sort of possible”. The odds of success will vary greatly.

Everybody knows what a PDF file is. It’s a Portable Document Format. This is actually a standard (ISO 32000). You don’t need Adobe products to create, edit, or read PDF-formatted documents. Odds are good that your distro comes with tools for manipulating PDF documents.

It’s possible to password-protect a PDF document. You can have an owner’s password (allowing editing) or you can have a user’s password (allowing you to read the document). This may be something you’ve encountered in the past.

Well, like all things password-protected, it’s possible to crack the password.

What do I mean by crack? I mean it will reveal the password to you in plain text. This will allow you to access the document in one form or another, depending on which password you crack.

This is gonna take some time…

Also, I’ll assume you’re using something based on Debian because I’ve not tested this with other distros. I’ve only tested this on my systems.

The tool we’ll be using is a ‘brute-force’ password cracker. That means it starts from the letter a and works its way up, adding new letters after the rest of the letters have been tried. So, you’ll see aa, ab, ac, ad, and progression along those lines. You can immediately see why this is going to take a while.

The tool we’ll be using is helpfully called ‘pdfcrack’.

pdfcrack:

This pdfcrack is a terminal-based PDF password-cracking tool. You can use brute force or lists of words such as common passwords. You can also specify the character list, though the default is to just use the regular alphabet in both uppercase and lowercase formats.

The pdfcrack application is helpfully described as such:

pdfcrack – Password recovery tool for PDF-files

I’ll assume that you’re only trying to recover passwords on documents you should legally have access to. I assume that you won’t use this to access content that does not belong to you. That seems like a safe assumption!

As you can see, this is the correct tool if you want to crack a PDF password.

Crack A PDF Password:

As mentioned above, you’ll crack passwords in the terminal. That requires an open terminal, so we might as well install pdfcrack in the terminal. Just press CTRL + ALT + T and that will usually open up a terminal for you.

With your terminal now open, install pdfcrack:

With that installed, check the man page:

Download:

Example PDF File

Now, crack it…

As it’s a download, it’s probably in your ~/Downloads directory, but mine is stored in my ~/Documents directory because it’s a document. So, my example:

That uses a very simple password that should be cracked in a few seconds. On my older and slower computer, I was able to do more than 20,000 words per second. This short password should crack almost instantly.

Leave a comment telling me what the password is!

By default, pdfcrack will crack the user password. You can specify which password you wish to crack. Though the syntax is a little wonky. In this case, the syntax is as follows:

Which translates into the following…

For the owner:

For the user:

If you want to pause this, you can! 

To pause a running pdfcrack instance just press CTRL + C. This will save the progress as savedstate.sav. The program will automatically resume when you run the command again. Pretty neat!

There’s a lot you can do with this command. Let’s say you recall the password was between 8 and 12 characters and want to just search in that area.

You can also specify the character set. If you want to use uppercase, lowercase, and numbers you can do that. You just add them to the command with the -c flag, making sure to put them in quotes. That’d look like this:

You can specify a wordlist like so:

The format for that file appears to require one word per line and there are collections of common passwords you can download to help you crack a PDF password.

As you can imagine, and as you were warned near the start, this process can take a while. Assuming you have the right characters loaded and enough time, it’s certain to work eventually.

Go ahead and crack my example file above. That one won’t take you very long, even on a slow computer. It won’t be instantaneous, but it’ll be pretty quick.

If you want, you can also run a benchmark to see how fast your computer is. The command to do that is quite simply this:

I ran this on the slowest computer I use. I didn’t run it on anything faster because I don’t care that much. I’m sure you’ll do better on your computers, though you can share the results as a way to compare your rig with others.

Anyhow, my output was this:

Be sure to check out the man page. It’s a simple application but there are many options available for pdfcrack and you might as well learn about them now. You never know when you’ll find an old PDF document with a forgotten password. It can (and does) happen!

Also, be sure to check the pdfcrack project page.

Closure:

So, you might wonder why I’d include an article like this. After all, isn’t cracking passwords a potential legal mess? Isn’t it immoral to crack passwords? Is it even legal to crack passwords?

The answer is simple enough. It’s a tool you can use to recover your lost passwords. You can use this tool to access things that you shouldn’t be accessing, just like you can use a screwdriver to poke things you shouldn’t be poking. I’m just giving information.

I am also not a lawyer. I permit you to crack the password of the included file. For other files, don’t do anything illegal in your jurisdiction. If it’s a crime, don’t do it. I’m decidedly not your lawyer. If you think this requires asking a lawyer, go ahead and do so.

That and it’s not a great secret. If you’re relying on a password to protect PDF files from anyone serious, you’re probably doing your security wrong. It’s well known that this is possible and that the tools are easily installed. PDF passwords aren’t very good for security, though you can make complicated passwords.

The distro you’re using may very well have pdfcrack available, even if it isn’t one of the Debian-based distros. Just search and you can find it. With some work, you can even mostly install it with PIP. Just click the link above to the project page for more information about that.

As always…

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 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.