Find out how to Scan Paperwork in Linux With SANE’s Most Helpful Instructions

Scanner Access Now Easy (SANE) is an API (Application Programming Interface) for controlling scanners and cameras. In use, the scanimage command line application can be used to quickly and reliably send scanner commands to perform a number of useful functions.

This is how you get the most out of SANE for scanning documents and photos.

Get healthy now

The API can be installed with your package manager. For example in a Debian system:

sudo apt install sane

… installs the SANE API and provides the scan image to the command line application. (It also installs the xscanimage, scanadf, and xcam front-end tools.) When you run the following command, it displays all of the options available:

Scan image -h

Now note that you can send API commands along with scanner-specific commands on the same command line. In addition, the output of -H can be a bit confusing as both API options and scanner options are only printed out in a chained style on the terminal.

If no scanner is detected you will only get the API options. When a scanner is detected, there may be a noticeable time lag while the information from the scanner device is retrieved, sent to the API, and formatted. The command seems to stop, but just wait and it will finish.

However, if you only want the device options ("backend" options for the scanner itself), you can use those -A Possibility:

Scan image -A

Note that SANE version 1.0.14-15 is used as an example for this article. Your particular version may vary and have slightly different options. If you have any questions, just run scanimage with the -H Possibility.

Of course, each scanner has its own options. So be sure to experiment with these to refine the commands you send and get the best results.

Related: How to Scan Old Slides with a Flatbed Scanner

Simple and easy SANE commands

Yes, easy and simple is what we all want. You have to start somewhere, and the simplest command to scan something is:

scanimage> scan_out

This works if your scanner is recognized by the API. In this case, the output is sent directly to standard out and then redirected to the scan_out file. The default setting for the image format is PNM, and the default setting for the mode (such as line art, black and white, or color) is set by the scanner. If the scanner is not recognized you will get this output (or something similar):

Scan image: No SANE devices found

You will also receive an information message regarding the output format that has not been set. This is only because the standard format for the image format is pnm. This can be changed to TIFF, PNG, or JPEG.

The output format is not fixed, with pnm being used by default.

Specify the output file

The standard output can also be redirected to a file > or you can issue an explicit option to provide the name and full path of the output file, for example:

scanimage -o scan_out.png

In this case, the API outputs an image in PNG format.

List and use devices

Would you like to make sure that your scanner is recognized by SANE? Run this command:

Scan image -L

All recognized devices are listed. If both a LAN and a USB connection are connected to a single device, they are listed on separate lines.

For example, an Epson WorkForce WF-3640 could be listed as follows:

Device `epson2: net: 'is an Epson PID 08B8 flatbed scanner
Device `epson2: libusb: 001: 005 'is an Epson PID 08B8 flatbed scanner

In this case, you can either use an address to send and receive data:

scanimage -d epson2: net: -o scan_out.png


scanimage -d epson2: libusb: 001: 005 -o scan_out.png

Note that the USB address changes if you disconnect and reconnect the USB port to a different port. In this case, you need to make sure that your device address matches the new address that was printed out when it is listed again.

Related: Best Photo Scanners for Backing Up Old Photos

Set a different picture format

If you want a different image format, you can run the same command as follows:

scanimage -o scan_out.tiff

SANE will try to guess the format based on the file extension. The format can also be specified explicitly with:

scanimage –format = tiff -o scan_out.tiff

or even that:

scanimage –format = tiff> scan_out

Batch commands

What more can you get out of the API? You can get: Batch commands to control an automatic document feeder (ADF) to scan pages sequentially.

While the scanner may only produce image formats, these can also be converted to text using an optical character recognition (OCR) application such as gocr.

Note that you may need to send scanner-specific commands to create a sufficiently detailed document for document retention or OCR conversion. These are given below.

Related: The Best Ways to Scan and Digitize Old Photos

An example of batch processing

You should use different formats depending on the purpose of the end result. For example, if the OCR application you plan to use only accepts PNM images, your image file format should be PNM.

Here is an example of sending a command to scan a page of printed text to be converted by an OCR application that accepts PNM images. In this command, the scanner-specific commands are –mode, –resolution, and –source:

scanimage –batch = document-A-% d.pnm –format = pnm –batch-count = 1 –mode Lineart –resolution 1200 –source Automatic

Since these are scanner commands and not the SANE API, they differ by make and model and may require some experimentation. For example, the following snippet may not be visible from the backend's help output:

–Source automatically

Scan it with SANE

Whether you are in possession of a pile of old family documents or a professional keeper, scanning with the SANE API is an obvious choice for media that can withstand the mechanical demands of scanners and ADFs.

Combine the functions of the SANE API with image post-processing or an OCR application and you can digitize almost any flat media that is worth preserving.

Control scanner under Linux With the SANE API

Do you need to access your scanner from a Linux desktop? You can use the SANE API to scan photos and documents on Linux.

Continue reading

About the author

Russ Frazier
(3 articles published)

By Russ Frazier

Subscribe to our newsletter

Subscribe to our newsletter for tech tips, reviews, free e-books, and exclusive deals!

One more step …!

Please confirm your email address in the email we just sent you.

Leave a Reply

Your email address will not be published. Required fields are marked *