Scan to PDF with command line under GNU/Linux

After years of not-so-good services, I deciced to replace my old Canon MG5550 printer/scanner combo. Instead, I bought a simple black and white laser printer/scanner, and I have never been so happy with a “printer”.

More info about the printer

Recently, I needed to go through quite some paperwork and I knew it would be a hassle (and pricey) do it with my actual hardware. Moreover, I was never happy with it: it was not reliable under Linux, there was no auto document feeder, etc.

So, I was looking for a new tool with the following requirements:

  • Linux support ;
  • Auto document feeder ;
  • Networked ;
  • Laser (for reduced cost of use) ;
  • Color not required.

After a few searchs, I came across this model :

It matches all my requirements, moreover it is just a little bigger than my previous printer which is a good point. I didn’t want a huge piece of plastic sitting on my desk.

Installing it under Linux / Macos and Windows was pretty straighforward. However, the only thing I did struggle with a bit was to find a good Linux program to scan document to PDF (I didn’t want to use Gimp and convert file manually to PDF).

Scan document to PDF with Linux

This is why I wrote a simple script (inspired from various pieces found on Internet).

What the script does :

  • scan one or several pages from the automatic document feeder and merge them into a single PDF file (optimized in size).


  • scanimage tool (part of sane backends and/or tools package) ;
  • libtiff-tools (or something similar in name) ;
  • imagemagick ;
  • ghoscript.

The script

NB : You’ll probably have to change the “device” part (-d flag) of the the scanimage command, in order to match your real device.


The script has be used has follow : path/to/save/your_file.pdf


In order to make things lazier, I am using an alias in my ZSH config:

Add the following line, to your .zshrc:

alias scan2pdf="bash ~/path/to/scripts/"

NB : in case your are using bash, add the above line to yout .bashrc file, and source the .bashrc file.

Which now, means I can scan a document like this, from anywhere:

scan2pdf path/to/save/your_file.pdf

That’s it!

Please bear in my mind that the script is pretty simple and stupid. It works very well for me, but it can be easily tweaked to your needs. If you do so, do not hesitate to share it with us.