Skip to the content.

47. Scanning


This chapter contains scanning applications which allow you to convert printed documents into formatted documents readable by other applications.

47.1 SANE-1.0.32


Introduction to SANE

SANE is short for Scanner Access Now Easy. Scanner access, however, is far from easy, since every vendor has their own protocols. The only known protocol that should bring some unity into this chaos is the TWAIN interface, but this is too imprecise to allow a stable scanning framework. Therefore, SANE comes with its own protocol, and the vendor drivers can’t be used.

SANE is split into back ends and front ends. The back ends are drivers for the supported scanners and cameras. The front ends are user interfaces to access the backends.

This package is known to build and work properly using an LFS 11.3 platform.

Back Ends Package Information

Additional Downloads (Front Ends)

Note

The upstream location for these files is at https://gitlab.com/sane-project but the file URLs use embedded md5sums. For convenience, the packages have been copied to the location above.

SANE Dependencies

Optional (Back Ends)

Avahi-0.8, Cups-2.4.2, libjpeg-turbo-2.1.5.1, libtiff-4.5.0, libusb-1.0.26, v4l-utils-1.22.1, Net-SNMP, libieee1284, libgphoto2, and texlive-20220321 (or install-tl-unx)

Optional (Front Ends)

a graphical environment, GTK+-2.24.33, and Gimp-2.10.32

User Notes: https://wiki.linuxfromscratch.org/blfs/wiki/sane

Kernel Configuration, Drivers and Additional Packages

To access your scanner, you will probably need the related kernel drivers and/or additional support packages. A SCSI scanner will need SCSI drivers, a parallel port scanner needs parallel port support (you should use enhanced EPP modes) and perhaps libieee1284, and a USB scanner will need the libusb-1.0.26 package. For HP devices, you may need hplip. Ensure you have the necessary drivers properly configured to access the devices.

Installation of SANE

Installation of SANE Back Ends

The SANE daemon should run with its own group. Create this group by issuing the following commands as the root user:

groupadd -g 70 scanner

Note

configure assumes that the user building SANE-backends is a member of the scanner group for testing the existence of this group. So the user building the package should be added to the scanner group. As the root user:

usermod -G scanner -a username

After adding the scanner group as above, you will need to log out and back in to activate it.

For a USB scanner, if you are linking to libusb-1.0.26, include the configure switch –enable-libusb_1_0. Install SANE-backends by running the following commands:

sg scanner -c "                  \
./configure --prefix=/usr        \
            --sysconfdir=/etc    \
            --localstatedir=/var \
            --with-group=scanner \
            --with-lockdir=/run/lock \
            --docdir=/usr/share/doc/sane-backends-1.0.32" &&
make

To test the results, issue: make check.

Now, as the root user:

make install                                         &&
install -m 644 -v tools/udev/libsane.rules           \
                  /etc/udev/rules.d/65-scanner.rules &&
mkdir -p          /run/lock/sane &&
chgrp -v scanner  /run/lock/sane

With the scanner on, run scanimage -L and the name and location of the device should appear. Of course, you need the device drivers configured, in order to run this test.

Installation of SANE Front Ends

The SANE-frontends package includes the graphical frontends xscanimage and xcam, and a command-line frontend scanadf. You don’t need this package if you intend to use one of the more advanced graphical frontends like XSane-0.999. For a list of frontend packages, see http://www.sane-project.org/sane-frontends.html.

To install SANE-frontends, use the following commands:

tar -xf ../sane-frontends-1.0.14.tar.gz &&
cd sane-frontends-1.0.14                &&

sed -i -e "/SANE_CAP_ALWAYS_SETTABLE/d" src/gtkglue.c &&
./configure --prefix=/usr --mandir=/usr/share/man &&
make

This package does not come with a test suite.

Now, as the root user:

make install &&
install -v -m644 doc/sane.png xscanimage-icon-48x48-2.png \
    /usr/share/sane

If GIMP was linked into the build and you wish GIMP to use xscanimage as a scanning plugin, issue the following command as the root user:

ln -v -s ../../../../bin/xscanimage /usr/lib/gimp/2.0/plug-ins

Note

If the plugin xscanimage is disabled in GIMP’s menu, in order to enable it, “create” a blank image using the menu or Ctrl-N. After that, it is enabled.

Command Explanations

sg scanner -c “…“: runs the command between double quotes with principal group scanner. This may be needed if the user has been newly added to group scanner, and has not logged out and in.

--sysconfdir=/etc: This switch installs the configuration files in /etc/sane.d instead of /usr/etc/sane.d.

--with-group=scanner: This parameter causes the directory created for the locking files to be group owned by the scanner group instead of the default uucp group.

exit: This command is used to exit the shell created by the su command.

Configuring SANE

Config Files

/etc/sane.d/*.conf

Configuration Information

Backend Configuration

The backend configuration files are located in /etc/sane.d. Information for configuring the various backends can be found by using the man(5) page for the desired backend. Run man sane-<backend>, substituting the desired backend.

Add any desired users to the scanner group.

If you want to access a network scanner, include two lines in net.conf, as root user (make sure to replace by the actual value, below):

cat >> /etc/sane.d/net.conf << "EOF"
connect_timeout = 60
<server_ip>
EOF

On the server side, include the client ip in the access list of /etc/sane.d/saned.conf, restart the saned daemon, and make sure the firewall, if any, is open to the client.

Frontend Configuration

If you use a desktop environment like Gnome or KDE you may wish to create a xscanimage.desktop file so that xscanimage appears in the panel’s menus. As the root user:

mkdir -pv /usr/share/{applications,pixmaps}               &&

cat > /usr/share/applications/xscanimage.desktop << "EOF" &&
[Desktop Entry]
Encoding=UTF-8
Name=XScanImage - Scanning
Comment=Acquire images from a scanner
Exec=xscanimage
Icon=xscanimage
Terminal=false
Type=Application
Categories=Application;Graphics
EOF

ln -svf ../sane/xscanimage-icon-48x48-2.png /usr/share/pixmaps/xscanimage.png
General Information

For general information about configuring and using SANE, see man sane. For information about USB scanning devices, run man sane-usb. For information about SCSI devices, run man sane-scsi.

Configuration and setup of the ‘saned’ daemon

The saned daemon is not meant to be used for untrusted clients. You should provide Firewalling protection to ensure only trusted clients access the daemon. Due to the complex security requirements to ensure only trusted clients access the daemon, BLFS does not provide instructions to configure the saned daemon. Some good (but outdated) information for setting up and securing the saned daemon can be found at https://penguin-breeder.org/sane/saned/.

Contents

Back Ends:

Installed Programs: gamma4scanimage, sane-config, saned, sane-find-scanner, and scanimage

Installed Libraries: libsane.so and numerous scanner backend modules

Installed Directories: /etc/sane.d, /usr/{include,lib,share}/sane, and /usr/share/doc/sane-1.0.32

Front Ends:

Installed Programs: scanadf, xcam, and xscanimage

Installed Library: GIMP plugin embedded in xscanimage

Installed Directories: None

Short Descriptions

gamma4scanimage creates a gamma table in the format expected by scanimage.

sane-config is a tool used to determine the compiler and linker flags that should be used to compile and link SANE.

saned is the SANE daemon that allows remote clients to access image acquisition devices available on the local host.

sane-find-scanner is a command-line tool to find SCSI and USB scanners and determine their device files. Its primary purpose is to make sure that scanners can be detected by SANE backends.

scanadf is a command-line interface to control image acquisition devices which are equipped with an automatic document feeder (ADF).

scanimage is a command line interface for scanning from image acquisition devices such as flatbed scanners or cameras. It is also used to list the available backend devices.

xcam is a graphical camera front end for SANE.

xscanimage is a graphical user interface for scanning.

libsane.so is the application programming interface that is used to communicate between frontends and backends.

libsane-*.so modules are backend scanning library plugins used to interface with scanning devices. See http://www.sane-project.org/sane-supported-devices.html for a list of supported backends.

47.2 XSane-0.999


Introduction to XSane

XSane is another front end for SANE-1.0.32. It has additional features to improve the image quality and ease of use compared to xscanimage.

This package is known to build and work properly using an LFS 11.3 platform.

Package Information

XSane Dependencies

Required

GTK+-2.24.33 and SANE-1.0.32 (back ends)

Optional

Little CMS-1.19 and Gimp-2.10.32

User Notes: https://wiki.linuxfromscratch.org/blfs/wiki/xsane

Installation of XSane

Install XSane by running the following commands:

sed -i -e 's/png_ptr->jmpbuf/png_jmpbuf(png_ptr)/' src/xsane-save.c &&
./configure --prefix=/usr                                           &&
make

This package does not come with a test suite.

Now, as the root user:

make xsanedocdir=/usr/share/doc/xsane-0.999 install &&
ln -v -s ../../doc/xsane-0.999 /usr/share/sane/xsane/doc

A browser of your choice can be used to get inline help, using the following command, as the root user:

ln -v -s <browser> /usr/bin/netscape

Note

Be sure to replace with the browser of your choice on your system.

Alternatively, if the environment variable BROWSER is set to the browser you want to use, eg, BROWSER=”/usr/bin/firefox”, the first time you run xsane, it will be recorded in ~/.sane/xsane/xsane.rc. If you wish to change it, edit this file, or remove it, and use the instructions above, so that a new one is created.

If GIMP is installed, issue the following command as the root user:

ln -v -s /usr/bin/xsane /usr/lib/gimp/2.0/plug-ins/

Command Explanations

ln -v -s ../../doc/xsane-0.999 /usr/share/sane/xsane/doc: This symlink is created to ensure that any program that looks for the XSane documentation in the default location will find it, as the documentation is installed in an alternate location specified in the make install command.

ln -v -s /usr/bin/xsane /usr/lib/gimp/2.0/plug-ins/: This creates a link in the system-wide GIMP plug-ins directory so that users can access XSane directly from GIMP. GIMP must be available before building XSane for this to work. Alternatively, create the link in ~/.gimp-2.0/plug-ins/ to provide individual user access. man xsane for additional information.

Contents

Installed Program: xsane

Installed Libraries: None

Installed Directory: /usr/share/doc/xsane-0.999 and /usr/share/sane/xsane

Short Descriptions

xsane is a graphical user-interface to control an image acquisition device such as a flatbed scanner.