How to Make and Combine PDF Files on the Linux Command Line


shutterstock 576831907
Jane Kelly/

PDF recordsdata have been designed to advertise sharing. Everybody can open them—of their internet browser in the event that they don’t have anything else. Linux helps you to manipulate, merge, and cut up PDF recordsdata on the command line.

The Transportable Doc Format

The Transportable Doc Format (PDF) solved an issue. Once you created a doc on a pc and wished to share it with another person, sending them the doc didn’t at all times work.

Even when that they had the identical software program bundle you’d used to create your doc, they won’t have the identical fonts put in on their pc that you just had on yours. They’d be capable to open the doc however it could look incorrect.

In the event that they didn’t have a duplicate of the software program you used to create the bundle they wouldn’t be capable to open it in any respect. If you happen to used software program that was solely out there on Linux, it was pointless sending that doc to somebody who solely used Home windows.

Adobe created a brand new file format in 1992 and referred to as it the moveable doc format. Paperwork created to that customary—ISO 32000—include the pictures and fonts wanted to accurately render the contents of the file. PDF recordsdata could be opened by PDF viewers on any platform. It was a cross-platform, easy, and stylish resolution.

A PDF file isn’t supposed to be malleable like a word-processor doc. They don’t readily lend themselves to modifying. If you must change the content material of a PDF, it’s at all times higher to return to the supply materials, edit that, and generate a brand new PDF. In distinction to making an attempt to alter the content material, structural manipulations could be carried out on PDF recordsdata with relative ease.

Listed below are some methods to create PDF recordsdata on Linux, and carry out a number of the transforms that may be utilized to them.

Creating PDF Information on Linux

Most of the purposes out there on Linux can generate PDF recordsdata instantly. LibreOffice has a button proper on the toolbar that generates a PDF of the present doc. It couldn’t be simpler.

The LibreOffice Writer PDF button

For fine-grained management of PDF creation, the Scribus desktop publishing utility is difficult to beat.

If you must create paperwork with scientific or mathematical content material, maybe for submission to educational journals, an utility that makes use of LaTeX, reminiscent of Texmaker, shall be good for you.

If you happen to favor a plain-text workflow, maybe utilizing Markdown, you should utilize pandoc to transform to, and from, an incredible many file codecs, together with PDF. We now have a information devoted to pandoc however a easy instance will present you the way simple it’s to make use of.

Set up Texmaker first. pandoc depends on some LaTeX libraries for PDF technology. Putting in Texmaker is a handy option to meet these dependencies.

The -o (output) choice is used to specify the kind of file that shall be created. The “” file is a plain-text Markdown file.

pandoc -o new.pdf

Using pandoc to create a PDF from a Markdown file

If we open the “new.pdf” file in a PDF viewer we see that it’s a correctly-formed PDF.

Opening the PDF created by pandoc

The qpdf Command

The  qpdf  command means that you can manipulate present PDF recordsdata, while preserving their content material. The adjustments you can also make are structural. With qpdf you possibly can carry out duties reminiscent of merging PDF recordsdata, extracting pages, rotating pages, and setting and eradicating encryption.

To put in qpdf on Ubuntu use this command:

sudo apt set up qpdf

Installing qpdf on Ubuntu

The command on Fedora is:

sudo dnf set up qpdf

Installing qpdf on Fedora

On Manjaro you have to kind:

sudo pacman -S qpdf

Installing qpdf on Manjaro

Merging PDF Information

At first, a number of the qpdf command line syntax could appear complicated. For instance, lots of the instructions anticipate an enter PDF file.

If a command doesn’t require one, you must use the --empty choice as an alternative. This tells qpdf to not anticipate an enter file. The --pages choice helps you to select pages. If you happen to simply present the PDF names, all pages are used.

To mix two PDF recordsdata to kind a brand new PDF file, use this command format.

qpdf --empty --pages first.pdf second.pdf -- mixed.pdf

Combining two PDF files to create a new PDF file

This command is made up of:

  • qpdf: Calls the qpdf command.
  • –empty: Tells qpdf there isn’t a enter PDF. You possibly can argue that “first.pdf” and “second.pdf” are enter recordsdata, however qpdf considers them to be command line parameters.
  • –pages: Tells qpdf we’re going to be working with pages.
  • first.pdf second.pdf: The 2 recordsdata we’re going to extract the pages from. We’ve not used web page ranges, so all pages shall be used.
  • : Signifies the top of the command choices.
  • mixed.pdf: The title of the PDF that shall be created.

If we search for PDF recordsdata with ls, we’ll see our two unique recordsdata—untouched—and the brand new PDF referred to as “mixed.pdf.”

ls -hl first.pdf second.pdf mixed.pdf

Using ls to list the existing and new PDF files

There are two pages in “first.pdf” and one web page in “second.pdf.” The brand new PDF file has three pages.

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

You should utilize wildcards as an alternative of itemizing an incredible many supply recordsdata. This command creates a brand new file referred to as “all.pdf” that accommodates all of the PDF recordsdata within the present listing.

qpdf --empty --pages *.pdf -- all.pdf

Using wildcards in the qpdf command line

We are able to use web page ranges by including the web page numbers or ranges behind the file names the pages are to be extracted from.

That is will extract pages one and two from “first.pdf” and web page two from “second.pdf.” Notice that if “mixed.pdf” already exists it isn’t overwritten. It has the chosen pages added to it.

qpdf --empty --pages first.pdf 1-2 second.pdf 1 -- mixed.pdf

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

Web page ranges could be as detailed as you want. Right here, we’re asking for a really particular set of pages from a big PDF file, and we’re making a abstract PDF file.

qpdf --empty --pages giant.pdf 1-3,7,11,18-21,55 -- abstract.pdf

Using a complicated set of page ranges

The output file, “abstract.pdf” accommodates pages 1 to three, 7, 11, 18 to 21, and 55 from the enter PDF file. This implies there are 10 pages in “abstract.pdf”

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

We are able to see that web page 10 is web page 55 from the supply PDF.

Splitting PDF Information

The alternative of merging PDF recordsdata is splitting PDF recordsdata. To separate a PDF into separate PDF recordsdata every holding a single web page, the syntax is easy.

The file we’re splitting is “abstract.pdf”, and the output file is given as “web page.pdf.” That is used as the bottom title. Every new file has a quantity added to the bottom title. The --split-pages choice tells qpdf what kind of motion we’re performing.

qpdf abstract.pdf web page.pdf --split-pages

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

The output is a sequence of sequentially numbered PDF recordsdata.

ls web page*.pdf

using ls to list the numbered PDF files

If you happen to don’t need to cut up out each web page, use web page ranges to pick the pages you need.

If we challenge this subsequent command, we’ll cut up out a group of single-page PDF recordsdata. The web page ranges are used to specify the pages or ranges we would like, however every web page remains to be saved in a single PDF.

qpdf giant.pdf part.pdf --pages giant.pdf 1-5,11-14,60,70-100 -- --split-pages

Splitting a PDF with page ranges

The extracted pages have names based mostly on “part.pdf” with a sequential quantity added to them.

ls part*.pdf

using ls to list the numbered PDF files

If you wish to extract a web page vary and have it saved in a single PDF, use a command of this way. Notice that we don’t embrace the --split-pages choice. Successfully, what we’re doing here’s a PDF merge, however we’re solely “merging” pages from one supply file.

qpdf --empty --pages giant.pdf 8-13 -- chapter2.pdf

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

This creates a single, multi-page PDF referred to as “chapter2.pdf.”

Rotating Pages

To rotate a web page, we create a brand new PDF that’s the identical because the enter PDF with the desired web page rotated.

We use the --rotate choice to do that. The +90 means rotate the web page 90 levels clockwise. You may rotate a web page 90, 180, or 270 levels. You can even specify the rotation in levels anticlockwise, through the use of a adverse quantity, however there’s no need to take action. A rotation of -90 is similar as a rotation +270.

The quantity separated from the rotation by a colon “:” is the variety of the web page you need to rotate. This may very well be a listing of web page numbers and web page ranges, however we’re simply rotating the primary web page. To rotate all pages use a web page vary of 1-z.

qpdf --rotate=+90:1 abstract.pdf rotated1.pdf

Rotating the first page of a PDF

The primary web page has been rotated for us.

A PDF file with the first page rotated 90 degrees clockwise

Encrypting and Decrypting

PDF paperwork could be encrypted in order that they require a password to open them. That password is known as the consumer password. There’s one other password that’s required to alter the safety and different permission settings for a PDF. It’s referred to as the proprietor password.

To encrypt a PDF we have to use the --encrypt choice and supply each passwords. The consumer password comes first on the command line.

We additionally specify the energy of encryption to make use of. You’d solely must drop from 256-bit encryption to 128-bit if you wish to help very outdated PDF file viewers. We advise you persist with 256-bit encryption.

We’re going to create an encrypted model of the “abstract.pdf” referred to as “secret.pdf.”

qpdf --encrypt hen.rat.squid goose.goat.gibbon 256 -- abstract.pdf secret.pdf

Creating an encrypted PDF

After we attempt to open the PDF, the PDF viewer prompts us for a password. Getting into the consumer password authorizes the viewer to open the file.

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

Do not forget that qpdf doesn’t change the present PDF. It creates a brand new one with the adjustments we’ve requested it to make. So in the event you make an encrypted PDF you’ll nonetheless have the unique, unencrypted model. Relying in your circumstances you would possibly need to delete the unique PDF or safely retailer it away.

To decrypt a file, use the --decrypt choice. Clearly, you have to know the proprietor password for this to work. We have to use the --password choice to establish the password.

qpdf --decrypt --password=goose.goat.gibbon secret.pdf unlocked.pdf

Creating a decrypted PDF from an encrypted PDF

The “unlocked.pdf” could be opened with no password.

qpdf is an Wonderful Instrument

We’re deeply impressed with qpdf. It gives a versatile and richly featured toolset for working with PDF recordsdata. And it is extremely quick, too.

Try their well-written and detailed documentation to see simply how rather more it could actually do.

Share post:



More like this