Ping Services

Saturday, March 5, 2011

Merge and rearrange PDF files on Linux and Windows

Have you ever wanted to delete or add a few pages to a PDF file? Or maybe even merge two PDF files together? What about merging all PDF files in a folder with a single short command? Here is a guide that will show you how.





Linux

PDF-Shuffler is a simple program that enables us to open PDF files, juggle a few pages around and export as a new PDF. It should be available for installation from your package manager.
Figure: PDF-Shuffler's GUI

After opening the program, we see nothing. Only the buttons import PDF, export PDF and delete pages are present, which showcases the simplicity of the program.

Figure: Rearranging pages in PDF-Shuffler

Afterwards, it is just a matter of opening the PDF files and performing the desired task.

But what if we have a folder full of PDF files that we would like to merge as one? Opening them all individually using PDF-Shuffler would be quite tiresome. Why go to all the hassle when there is a command line tool that can can perform the task in a couple of seconds?

Pdftk is such a program, probably located in your repositories.  Here are some examples of how one can use this program:

1. Combining files

A.) Combining a few files by name:
The syntax for such a command would be:

pdftk file1.pdf file2.pdf file3.pdf cat output outputfile.pdf.

B.) Combining all files in a folder:
However, when one is faced with combining more than just a few PDF files, it is far easier to use this syntax:

pdftk *.pdf cat output outputfile.pdf.

2. Spitting files

If one would like to split a PDF file by extracting certain pages, it is possible to use another command. We can use naming here and name a file as A, and then specify which pages to extract.

pdftk A=file1.pdf cat A1-5 A6 output outputfile.pdf

3. Rearranging files.
It is possible to not just extract some pages, but it is also possible to combine them with pages from other PDF documents. Again, we can use naming.

pdftk A=file1.pdf B=file2.pdf cat A1-5 B1-5 A6 output outputfile.pdf

Windows

On Windows, a tool called PDF-Jumbler is available and it is very similar to PDF-Shuffler. It is available for download as a .jar file [1], which means that you will need the Java runtime environment to run it [2].

Upon opening the program, the interface seems to be very simple to use.

Now it is easy for us to open a few files and rearrange/delete pages to create a new PDF file. What I liked about PDF-Jumbler was the zoom buttons that allowed you to take a closer look at what you are doing. It's a small thing, but these small things matter.

I hope you found this article useful. And just as an aside, I apologize for not updating for 15 days as I was extremely busy doing assignments and studying for tests these past two weeks. I hope that I have enough free time to release the next article a bit sooner.

Links
[1] Download PDF-Jumbler
[2] Download Java Runtime Environment

No comments:

Post a Comment