Home > programming > How to “stick” several PDF’s into 1 document

How to “stick” several PDF’s into 1 document

I had some paperwork that I needed to scan and email out for my son’s kinder. Scanning was easy, even with some OCR, the scanner automatically created 4 separate PDF documents. Now to bring them into 1 document, hmm? Let’s try google.

Sure every man and his dog is suggesting methods under searches like “merge pdf documents” from how to articles that say to click on the “combine” menu item, which seems not to apply to my Mac all the way through to a bunch of shareware/freeware/paid software. But how do you know which is best? which one is safe? and which one is worth the purchase? for something this small nothing. I don’t want to go through the pain of working this out, trying some software, only to find out it will water mark the result or something.

Why not write it myself? I am playing around with the groovy programming language at the moment so why not try that? I took a look, “groovy pdf library” of course with a name like that I found a lot of groovy “really cool” PDFs. As Groovy works seemlesslly with Java and the JVM, next stop was searching for “java pdf library” a few other libraries made the front page but everything seemed to point to iText. It looks pretty comprehensive, there is even an “iText in action” book available. I start looking at the documentation and decide it is too much. I just want to merge 4 PDFs into 1 and I don’t want to use any more then 4 lines!

Time to have a look at the root of my scripting knowledge, Perl. Soon enough I found PDF::Reuse and its prDoc command. The result is

1
2
3
4
5
6
7
8
9
10
11
12
13
#!/usr/bin/perl
use warnings;
use strict;
use PDF::Reuse;
 
prFile("kinderNewsletter.pdf");
 
prDoc('kinderScan_01.pdf');
prDoc('kinderScan_02.pdf');
prDoc('kinderScan_03.pdf');
prDoc('kinderScan_04.pdf');
 
prEnd();

I later also found that there is some unix command line tool pdftk which would have done the same but I would need to install that and work out how to use it, maybe next time.

  1. No comments yet.
  1. No trackbacks yet.