Introduction: Inserting an Image Into an Existing PDF And/or Converting Multiple Images to Pdf

I needed to insert an image (a photo of a signature) into an existing PDF. There are tons of tools that cost something, crippled 2-page "free" converters or online web services that will make you tear your hair out. So here’s how to do this for free. I must warn that it takes some command line and open source hacking around.

Step 1: Convert the Pages in the PDF to Separate TIFF Files

Convert the pages in the PDF to separate TIFF files. I did this with the free GIMP program. It runs on just about any operating system, so that shouldn’t be a problem. GIMP gives you several options for importing the PDF pages. Be sure to adjust the resolution to something like 300 dpi and select Open pages as images. Unless of course you love layers and know exactly what you’re doing. Warning! If you go for a default resolution of 100 dpi, you might lose some quality. Don’t worry if you get gigantic TIFF files. They’ll be compressed back later.

Step 2: Add the Image You Want to Insert to the Appropriate TIFF File(s)

Within GIMP edit the page you want to insert something into. If you can’t work with GIMP, edit the appropriate TIFF in your favorite image editing program. Either way, you should end up with a separate TIFF for every page in your PDF. Exporting to TIFF in GIMP is easy if you know how. File – Export As… and then Select File Type (TIFF Image). Check if your TIFFs are all beautiful. They should have increasing names, like page01.tif, page02.tif, etc.

Step 3: Install ImageMagick

Move all the TIFFs to a single temporary directory that you can access from your command line. Now we can do this in OSX or Linux. I happen to have both on my Macbook Pro. If you don’t have at least one Linux distribution at your disposal, it is time to change this. In this day and age one meddling with computers should at least know some basic Linux. The command we need is convert and it is part of a wonderful open source program called imagemagick. To install imagemagick in OSX I highly recommend homebrew. First we run of course:

osx_prompt$ brew update  

Then followed by:

osx_prompt$ brew install imagemagick  

Of course osx_prompt$ is the name of your OSX Terminal prompt. If you're stuck at this step because you haven't the foggiest clue as to what homebrew is, it is "the missing package manager" for OSX. It is a free tool. You can install it in OSX with this command:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

In Linux (Debian in my case), you can install imagemagick via Aptitude (as a super user):

root@debian:/home/your_name# apt-get install imagemagick

Step 4: Combine TIFFs Back Into a Pdf

In the Terminal of our choice, we now cd (change directory) to the directory where all the TIFFs are and execute the command:

root@debian:/home/your_name# convert -compress LZW *.tif new.pdf  

Or you may choose to run this as a normal Terminal (not a super user/root), because your Desktop probably is not “root@debian” so you might find that your pdf is now not owned by you.

Also in OSX you can now simply run:

osx_prompt$ convert -compress LZW *.tif new.pdf  

There it is, a beautiful PDF to mail to the eagerly waiting other party! Two things to note:

  1. We do an LZW compress because else the PDF would be of monster size. Especially for b&w page scans you can compress a lot using LZW compression.
  2. If all your TIFFs end with .tiff (instead of *.tif), you can say
convert -compress LZW *.tiff new.pdf

In the case you see this error:

convert: no decode delegate for this image format `TIFF' @ error/constitute.c/ReadImage/501.
...you can always try to convert your TIFFs to JPG and combine JPG's instead.