Fast image processing with ExactImage
Searchable PDFs
The hocr2pdf
program lets you create searchable PDFs from scanned originals. In principle, these PDFs consist of two levels: One is occupied by the scanned image, and a second – often invisible underneath – contains the resulting text from OCR processing. Searching is done against this second level; it thus needs to match the graphical level as accurately as possible.
A number of programs use hocr2pdf
to create PDF "sandwiches" of this kind. These include, for example, pdfocr
, the largely automated pdfsandwich
[4], xsane2sandwich
[5], and djvu2pdf
[6], which extracts an hOCR file from DjVu data and creates a searchable PDF. How well this works is shown in Figure 3, in which the recognized words are highlighted by blue boxes.

Using hocr2pdf
is relatively simple, although it does expect the hOCR data via the standard input channel (Listing 4, first line). You can generate the hOCR files with Cuneiform or Tesseract and edit them with the hOCR tools [7] if necessary. If the text alignment does not match the scanned image, this can be adjusted in hocr2pdf
with the -s
(--sloppy-text
) option (Listing 4, line 2).
Listing 4
Using hocr2pdf
The hocr2pdf
tool only supports a few options other than this; everything else is done automatically. The -i
switch defines the graphical input file and -o
the final output file. The -n
option lets you prevent the integration of a graphical layer, and -r
sets the resolution for it; hocr2pdf
uses 300dpi by default.
Conclusions
For more complex transformations – for example, splitting a PDF file into individual images or comparing two images – you will still probably need to turn to ImageMagick or GraphicsMagick: ExactImage is not much help here. This also applies to identifying specific image formats; although edentify
returns results, they do not stand comparison with the quality that identify
will give you.
If you are more interested in the typical tasks of converting and editing popular formats, ExactImage offers a quick, easy-to-use alternative to the more complex tools in many cases. The hocr2pdf
program proves to be a true gem that many other tools use under the hood.
Infos
- ImageMagick: http://imagemagick.org
- GraphicsMagick: http://www.graphicsmagick.org/
- ExactImage: http://www.exactcode.de/site/open_source/exactimage/
- Pdfsandwich: http://www.tobias-elze.de/pdfsandwich/
- Xsane2sandwich: http://wiki.ubuntuusers.de/xsane2sandwich
- Djvu2pdf: http://0x2a.at/s/projects/djvu2pdf
- hOCR tools: https://github.com/tmbdev/hocr-tools
« Previous 1 2
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Direct Download
Read full article as PDF:
Price $2.95
News
-
System76 Teams up with HP to Create the Dev One Laptop
HP and System76 have come together to develop a new laptop, powered by Pop!_OS and aimed toward developers.
-
Titan Linux is a New KDE Linux Based on Debian Stable
Titan Linux is a new Debian-based Linux distribution that features the KDE Plasma desktop with a focus on usability and performance.
-
Danielle Foré Has an Update for elementary OS 7
Now that Ubuntu 22.04 has been released, the team behind elementary OS is preparing for the upcoming 7.0 release.
-
Linux New Media Launches Open Source JobHub
New job website focuses on connecting technical and non-technical professionals with organizations in open source.
-
Ubuntu Cinnamon 22.04 Now Available
Ubuntu Cinnamon 22.04 has been released with all the additions from upstream as well as other features and improvements.
-
Pop!_OS 22.04 Has Officially Been Released
From the makers of some of the finest Linux-powered desktop and laptop computers on the market comes the latest version of their Ubuntu-based distribution, Pop!_OS 22.04.
-
Star Labs Unveils a New Small Format Linux PC
The Byte Mk I is an AMD-powered mini Linux PC with Coreboot support and plenty of power.
-
MX Linux Verison 21.1 “Wildflower” Now Available
The latest release of the systemd-less MX Linux is now ready for public consumption.
-
Microsoft Expands Their Windows Subsystem for Linux Offerings With AlmaLinux
Anyone who works with Windows Subsystem for Linux (WSL) will now find a new addition to the available distributions, one that’s become the front-runner replacement for CentOS.
-
Debian 11.3 Released wIth Numerous Bug and Security Fixes
The latest point release for Debian Bullseye is now available with some very important updates.