Two ways to merge PDF files on Mac (GUI and command line)

This post introduces how to merge PDF files on Mac from GUI and from Terminal on Mac OS.

(For Ubuntu and Windows users, check out my post here for solutions.)

Method 1: GUI — using Preview  that comes with your Mac OS.

Check here for how to combine PDFs and reorder, rotate, and delete pages. If the page is not accessible, check the pdf I linked to in the references.

Method 2: From Terminal

We will introduce using gs command.

many people may already have gs package  installed and are already using gs.

TO check whether your Mac has gs installed,  in your terminal, issue the following command:

$ which gs

If you see something like this “/usr/local/bin/gs”, you OS has gs installed

If you see something like “… command not found”, you will need to install gs first.

You can use brew to install it.

$ brew install gs

If you do not have brew installed, check: Install Homebrew.

After you have gs installed,

in your terminal, cd to the directory where the pdf files you want to merge are located, and then issue the following command:

$ gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=merged.pdf source1.pdf source2.pdf source3.pdf

Then you will see a merged.pdf appear in the same folder where you source pdfs are.

Note: You may encounter these two errors in your terminal after your issue the pdf merge command I mentioned above, but be assured, the merge.pdf is correct. you can double check if you are worried about that:)



Use Preview to combine PDFs on your Mac (pdf)

How can I combine multiple PDFs using the command line?


Word count in pdf using wc command (on Ubuntu and Mac)

This post introduces how to count the number of words in a pdf file using wc command. It works on both Linux (Ubuntu) and Mac OS.

Note: you do not need to install anything, it is built-in on your Ubuntu/Mac OS.

Step 1: open a terminal 

Step 2: cd to the directory where your pdf file is located 

Step 3: issue the following command

$ ps2ascii example.pdf | wc -w

Step 4: Then you should see the number of words in that example.pdf


P.S.   the wc command has several arguments, see below.

wc -l: print the number of lines in a file.

wc -w: print the number of words in a file.

wc -c: print the number of bytes in a file.

wc -m: print the number of characters from a file.

wc -L: print only the length of the longest line in a file.




Free tools to merge and split PDF files on Ubuntu and Windows

This post provides some GUI and command line tools to merge and split PDF files on Ubuntu and Windows.

(For Mac users, check out my post here for solutions.)

  • PDF-Shuffler is a GUI package that allows us to merge, split and re-arrange pages from PDF documents

Install use the command in your terminal (I have tested, It works on Ubuntu 16.04 LTS.)

sudo apt-get update
sudo apt-get install pdfshuffler

It is pretty simple and straightforward to use.


If you try to merge pdf files that are encrypted, you will meet this error.

*.pdf is encrypted.
Support for encrypted files has not been implemented yet.
File export failed.
  • PDFtk is a simple and powerful command line tool for doing everyday things with PDF documents. It comes in three flavors: PDFtk Free, PDFtk Pro, and the original command-line tool PDFtk Server. There is a simple GUI free versio for Windows users, see below for the info.

Install use the command in your terminal (I have tested, It works on Ubuntu 16.04 LTS.)

sudo apt-get update
sudo apt-get install pdftk

If you are a windows user, you do not need to buy adobe pdf pro version to manipulate pdf files any more, see the link to download PDFtk free, it is a simple GUI package to use on Windows. See the picture below for a sense of it.


See below for examples of using PDFtk to manipulate PDF files via linux command line.

This tool lets you do all sorts of things with PDF documents, such as split, merge or rotate them, apply a background watermark, burst documents into single pages, etc. mostly used command: use pdftk to split PDF files, use the following command :

pdftk in.pdf cat 2-8 output out.pdf

This will extract pages 2 through 8 from in.pdf and save them as out.pdf. The input file in.pdf will not be altered. You can use any other page range in place of 2-8. Leave out the range to select the whole document.

And here is an example of how to merge PDF files:

pdftk in1.pdf in2.pdf cat output out.pdf

This will concatenate in1.pdf and in2.pdf, saving the result as out.pdf. If you want to merge individual page ranges, you have to assign handles to input files, like so:

pdftk A=in1.pdf B=in2.pdf cat A2-3 B4-5 \

output out.pdf

This will merge pages 2-3 from in1.pdf with pages 4-5 from in2.pdf into out.pdf. The backslash means that the input is continued on the next line. You can use it when you type in long commands, but you don’t have to.


pdftk in.pdf cat 1-12 output in_page1-12.pdf
pdftk in.pdf cat 15-end output in_page15-end.pdf

You can use this method to split a PDF in N ways, or to remove pages.

For example, to remove page 13:

pdftk in.pdf cat 1-12 14-end output out.pdf

Or use it to rotate pages and many other things, type man pdftk in your command to see the options.

Installation is also possible by downloading a binary (Windows, OS X, Linux) or using Homebrew.


  • cpdf, it is a powerful, free tools to manipulate PDF files using command line. The Coherent PDF Command Line Tools allow you to manipulate existing PDF files in a variety of ways. For example:
  • Merge PDF files together, or split them apart
  • Encrypt and decrypt
  • Scale, crop and rotate pages
  • Read and set document info and metadata
  • Copy, add or remove bookmarks
  • Stamp logos, text, dates, page numbers
  • Add or remove attachments
  • Losslessly compress PDF files

See below for some examples:

cpdf in.pdf 1-12 -o out.pdf

cpdf in.pdf 13-end -o out.pdf

Or, to split into 12-page-sized chunks:

cpdf in.pdf -split -chunk 12 -o out%%%.pdf

Note that: for a large pdf file (1000+ pages) the performance of cpdf was much better than PDFtk.


Edit PDF files on Linux – the easiest way

Sometimes you run up in a situation when you need to edit a PDF file on Linux. For example, when you need to go through an old report which was in PDF format and you saw some typos. how to edit PDF files on Ubuntu?

I remembered that I used a program called pdfedit but it’s not available on Ubuntu or in any other Linux distributions anymore.

Things change now. In the past, we needed to use a dedicated application for this purpose. There are still plenty of tools to edit PDF files on Linux, but we don’t really need them, well not in most of the cases, because LibreOffice does the job for us.

Surprised? Yes, the popular Linux alternative to Microsoft Office can also edit PDF files. And perhaps this is the easiest way for editing PDF files.

 How to Edit PDF files on Linux
Most of the Linux distributions such as Ubuntu, Linux Mint, Fedora etc has LibreOffice as default office suite. If you do not have LibreOffice, you can install it.

Once you have installed LibreOffice, Use LibreOffice Draw to open the pdf file to edit. You will see that the file is in editable mode. You can use the select pointer to choose which bit of text to edit. Just click on the text which you want to edit. For those areas that are no text, you will need to use draw tool (e.g., pencil, circle etc.) to add things.

Once you are done with the edits, instead of saving the file (using Ctrl+S) option, click on Export to PDF button.

If you are not finising the edit yet, but need to save the editted file, save it and it will be saved as a .odg file. Next time you would like to continue the edit, just open the .odg file, you will be able to continue your edits.

It is pretty cool, right? We do not need to buy Adobe Pro version to edit pdf files any more.

Limitations of editing PDF files with Libreoffice.

This PDF editing does not work on scanned documents. The files which were originally created as text and saved as PDF can be edited very easily but it is not the case when you have scanned document because those pages are actually images. But you can use draw tools (e.g., pencil, circle) in the Libreoffice to add things like signature, tick sign etc, you just cannot edit the text part if it is a pdf file from scanning.