Quick Links
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 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.
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.
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.
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.
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.
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.
This tellsqpdfnot to expect an input file.
The–pagesoption lets you choose pages.
If you just provide the PDF names, all pages are used.
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.
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.
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.
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.
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.
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.”
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.
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.
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.
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.
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.”
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.
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.
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.
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.
And it is very fast, too.
Check out theirwell-written and detailed documentationto see just how much more it can do.