PDF files were designed to promote sharing.

Everyone can open them—in their web online window if they have nothing else.

Linux lets you manipulate, merge, and split PDF files on the command line.

The LibreOffice Writer PDF button

The Portable Document Format

The Portable Document Format (PDF) solved a problem.

They’d be able to launch the document but it would look wrong.

Adobe created a new file format in 1992 and called it the portable document format.

Using pandoc to create a PDF from a Markdown file

PDF files can be opened by PDF viewers on any platform.

It was a cross-platform, simple, and elegant solution.

A PDF file isn’t intended to be malleable like a word-processor document.

Opening the PDF created by pandoc

They don’t readily lend themselves to editing.

It couldn’t be easier.

For fine-grained control of PDF creation, theScribusdesktop publishing program is hard to beat.

Installing qpdf on Ubuntu

We havea guide dedicated to

but a simple example will show you how easy it is to use.

relies on some LaTeX libraries for PDF generation.

Installing Texmaker is a convenient way to meet those dependencies.

Installing qpdf on Fedora

The

(output) option is used to specify the bang out of file that will be created.

The “raw-notes.md” file is a plain-text Markdown file.

The qpdf Command

Theqpdfcommand allows you tomanipulate existing PDF files, whilst preserving their content.

Installing qpdf on Manjaro

The changes you’ve got the option to make are structural.

For example, many of the commands expect an input PDF file.

If a command doesn’t require one, it’s crucial that you use the–emptyoption instead.

Combining two PDF files to create a new PDF file

This tellsqpdfnot to expect an input file.

The–pagesoption lets you choose pages.

If you just provide the PDF names, all pages are used.

Using ls to list the existing and new PDF files

To combine two PDF files to form a new PDF file, use this command format.

There are two pages in “first.pdf” and one page in “second.pdf.”

The new PDF file has three pages.

The new PDF file has all the pages from the two original PDF files

you’ve got the option to use wildcards instead of listing a great many source files.

This is will extract pages one and two from “first.pdf” and page two from “second.pdf.”

Note that if “combined.pdf” already exists it isn’t overwritten.

Using wildcards in the qpdf command line

It has the selected pages added to it.

Page ranges can be as detailed as you like.

Splitting PDF Files

The opposite of merging PDF files is splitting PDF files.

Using page ranges to select the pages to add to the new file

To split a PDF into separate PDF files each holding a single page, the syntax is simple.

This is used as the base name.

Each new file has a number added to the base name.

Using a complicated set of page ranges

The–split-pagesoption tellsqpdfwhat pop in of action we’re performing.

The output is a series of sequentially numbered PDF files.

If we issue this next command, we’ll split out a collection of single-page PDF files.

Page 10 of the new PDF is page 55 from the source file

The extracted pages have names based on “section.pdf” with a sequential number added to them.

Note that we don’t include the–split-pagesoption.

This creates a single, multi-page PDF called “chapter2.pdf.”

Splitting a PDF file into many PDF files of one page each

We use the–rotateoption to do this.

The+90means rotate the page 90 degrees clockwise.

you’re able to rotate a page 90, 180, or 270 degrees.

using ls to list the numbered PDF files

A rotation of -90 is the same as a rotation +270.

To rotate all pages use a page range of1-z.

The first page has been rotated for us.

Splitting a PDF with page ranges

Encrypting and Decrypting

PDF documents can be encrypted so that they require a password to open them.

That password is called the user password.

There’s another password that’s required to change the security and other permission configs for a PDF.

using ls to list the numbered PDF files

It’s called the owner password.

To encrypt a PDF we need to use the–encryptoption and provide both passwords.

The user password comes first on the command line.

Extracting a range of pages from a PDF file and storing them in one new PDF file

We also specify the strength of encryption to use.

We suggest you stick with 256-bitencryption.

We’re going to create an encrypted version of the “summary.pdf” called “secret.pdf.”

Rotating the first page of a PDF

When we attempt to initiate the PDF, the PDF viewer prompts us for a password.

Entering the user password authorizes the viewer to fire up the file.

Remember thatqpdfdoesn’t change the existing PDF.

A PDF file with the first page rotated 90 degrees clockwise

It creates a new one with the changes we’ve asked it to make.

So if you make an encrypted PDF you’ll still have the original, unencrypted version.

Depending on your circumstances you might want to delete the original PDF or safely store it away.

Creating an encrypted PDF

To decrypt a file, use the–decryptoption.

Obviously, you must know the owner password for this to work.

We need to use the–passwordoption to identify the password.

A PDF viewer promtping for the password to open an encrypted PDF file

The “unlocked.pdf” can be opened without a password.

qpdf is an Excellent Tool

We’re deeply impressed withqpdf.

It provides a flexible and richly featured toolset for working with PDF files.

Creating a decrypted PDF from an encrypted PDF

And it is very fast, too.

Check out theirwell-written and detailed documentationto see just how much more it can do.