This article describes how to build a document batch scan system. To achieve this goal, we will use many Linux tools. The advantage of this method is that this process can be customized to meet your specific needs. This provides you with a set of major tasks that can be processed, and flexible. This article will show you how to build a batch scanning system for documents. To achieve this goal, we will use many Linux tools. The advantage of this method is that this process can be customized to meet your specific needs. This provides you with a set of systems that can handle major tasks and be flexibly customized.
We will focus on two possible final products: each page is a PDF file of the original page, and a text file containing the original page text content. The content of a text file can be searched. we have discussed several methods for converting a text file into a PDF file.
This tutorial is modular. For example, if you are processing a set of pre-scanned images, you can skip the first few steps and directly go to the optical character recognition (OCR) software to process the images, or convert them into PDF files. Similarly, if you prefer to use a graphical user interface (GUI) tool to process some links in this process, there is nothing to block you. Even so, we try to make every step of this process be capable of writing scripts to achieve full automation.
By fully using the command line-based tool, we can ensure that every stage of the project can be customized and scripts can be written.
- Related Resources
- Linux machine
- Scanner
- Procedure
Step 2: install SANE
You can use the package manager to install the main Scanner package SANE (Scanner Access Now Easy ). If you have installed SANE, but it is still difficult to access the scanner, there may be SANE backend tools for specific vendors on the Internet. If this is the case, use Google to search.
Step 2: Find the scanner
Type the scanimage-L command in the command line to check whether SANE is compatible with your scanner. If your scanner is supported, the text output will contain the device name. What you need is the first element before the colon.
Step 2: scan images
Type scanimage-d [Device Name]> test. pnm to quickly test and scan an object. This will use the default settings to scan a page of content. Open the scanned file in the graphic viewer and check it. If a problem occurs, you can add the-v option for troubleshooting.
Step 2: improve scanimage options
If you plan to use OCR to process text or do not need color, 300 DPI resolution and black/white are two typical options. First, this reduces the file size. Scanimage-d [device name]-format = tiff-mode Lineart-resolution and 300> [file name] are two typical options.
Step 2: Create a scan script
We will use the command line string for scanning to create the first script. Use a text editor to create a file named scan. sh. Add #! /Bin/bash is the first line. Add your scanner series as the second line. Save the file. Type chmod + x scan. sh in the command line to make the script executable. Type./scan. sh to the terminal to run it. Next, we can create additional scripts like this at the necessary stage. You can combine these scripts into a long script or call different stages separately.
Step 2: calculate the crop size
You don't have to worry about rotating documents at this stage. You can use the package manager to install GIMP. Open the scan document in GIMP and select the cropping tool from the tool panel. Let the cropping area overwrite the valid part of the document, and then remember the cropping size in the cropping dialog box. If you want to split an onhead page into different pages, you need to write down the appropriate page size. Don't crop in GIMP, because we will crop it from the command line later.
Step 2: install ImageMagick
Use the package manager to install ImageMagick on your system. We use the convert command to interact with this image processor tool. We can use it to rotate and crop images, and use it to split pages. Note: convert uses a single break number before the option.
Step 2: crop the page
Execute the cropping task by using the relevant parameters obtained by using GIMP. Type convert [image name] + repage-crop [x width] x [y width] + [x offset] + y [offset] [Output name]. For example, convert page1.png + repage-crop 2244x3113 + 1 + 1 page1_crop.png will crop the rectangular page starting from the top and one pixel on the left and with a size of 2244x3113.
Step 2: rotate the page
If you have to scan the page on both sides, use ImageMagick to rotate the page. Convert [input name]-rotate 90 [Output name] can complete this task.
Step 2: split the front page
As before, use the GIMP cropping function to calculate the exact size of the cropping page. Convert page1.tiff + repage-crop 2233 × 1579 + 0 + 1529 page1_a.tiff and subsequent convert page1.tiff + repage-crop 2233 × 1546 + 0 + 0 page1_ B .tiff, you can create two different files from two header pages.
Step 2: Create a pre-processed script
The above is an example of a pre-processing script. It creates a directory named splits, rotates each scan, and splits it into two pages numbered in order. Finally, it deletes the rotated object. Save it, and type the chmod + x command to make it an executable script.
Step 2: scanner batch processing mode
Use the-batch series option for multiple pages. If you do not have a paper dispenser, add the-batch-prompt option so that the prompt is displayed between each scan. In addition, you can add-batch =./$ page _ % 03d. tiff to provide the name of the file starting with "page" and ending with a number with three zeros.
Step 2: Pre-crop in Scanner
You may be able to crop pages in the scanner, which can lead to smaller files and faster operations, because the scanning head does not have to scan a long distance. Use the cropping tool in GIMP to change the unit from px (pixel) to mm (mm) in the dialog box to calculate the size and offset you need. If the results prove that the information obtained in this way is not accurate, you may consider using the original method to use a ruler. On the scanimage command line, the format of the additional flag is-l [left]-x [width]-t [top]-y [height].
Step 2: dual-sided document
If you want to scan dual-sided documents, use the previously mentioned batch option, but add the-batch-double option to increase the number of pages by two. During the second scan, perform the same operation again on the other side, but add-batch-start = 2 to increase the number.
Step 2: convert a scanned copy to PDF
You can use ImageMagick to convert directories filled with scanned images into PDF "books ". The convert *. tiff output.pdf command creates a multi-page document. If you need to insert the title page, name it page000.tiff and put it in this directory.
Step 2: Use Tesseract to process text with OCR
Try the OCR engine on the test page. To do this, type tesseract [input file name] [output file]. Do not add a file extension to the output file name, because the file extension will be added by Tesseract. Note: Tesseract can detect multiple columns and header pages.
Step 2: OCR batch processing
Use the following Bash code to process the Directory of the page filled with scans using OCR: for I in *. tiff; do tesseract $ I outtext $ I; done; the final result is a set of text files. Use cat *. txt> [output text files] to combine these files.
Step 2: Text formatting
By default, Tesseract inserts the carriage return to the same location in the source text. You can use the following command: fmt-u [input file]> [output file] to create a new text file format.
Step 2: edit text in LibreOffice
You only need to paste the output results obtained from the previous steps to LibreOffice Writer. In this phase, you can control editing and manually edit parameters such as the node header. You can even insert images from the original document.
Step 2: export a PDF file from LibreOffice
LibreOffice has some built-in tools for creating PDF files. If you final the layout and format, go to File> Export as PDF (exported as PDF File ). Click Export to get a name for the document.
Step 2: create a PDF file of the script
Use the package manager to install the iconv, ps2pdf, and enscript packages. Type iconv-f UTF-8-t ISO-8859-1-c [input text file] [output text file] to prepare the text file. Type enscript [text file]-p [output postscript file. ps]. Type ps2pdf [. ps file] to convert PostScript to PDF.
Link: http://www.linuxuser.co.uk/tutorials/automatic-mass-scanning-of-documents-tutorial