Package: scan-to-paperless
Scan and prepare your document forPaperlessThe main goal of this project is to have some productive process from the document scanning toPaperless.
For that we need to prepare the documents some tools that need many resources, then the idea to do it
in the background and ideally on another host like a NAS.
A consequence of that it's a not easy to put it in place, but then you will be really productive.
The interface between the user and the process is thescancommand to do the initial scan, and the file system
to verify that the result is OK (and do some advance operations describe below) and validate it.FeaturesScan the images optionally by using the Automatic Document FeederEasily scan double-sided images using the Automatic Document FeederExtract the DPI from the TIFF imagesChange the images levelsRemove the area out of the imageDeskew the imagesCrop the imagesSharpen the images (disable by default)Dither the images (disable by default)Auto rotate the images by using tesseract (To have the text on the right side)Optimize the images usingpngquant,optipng,ps2pdforjpeg(using quality from GraphicsMagick convert)Assisted split, used to split a prospectus page in more pages (Requires to modify the YAML...)Append credit cart, used to have the two faces of a credit cart on the same pageBe able to copy the OCR result from the PDFScan the QR code and Bar code and add a new page with the values (separate process)Manage the empty lines in the QR code (replace by a pipe (|) in the PDF,
and runscan --convert-clipboardto scan your clipboard to do the inverse transform)RequirementsOn the desktop:Python>= 3.6Thescanimagecommand, on Windows it should be able to use another command,
but it's never be tested.
This command would be an adapter that interpret the following arguments:--batch,--batch-start,--batch-increment,--batch-count,--batchfor the destination file name template (%dis replaced by the page number),
and the others for theauto_bash.On the NAS:DockerInstallScan-to-paperless requires a desktop and a server part, the two parts communicate through the scan folder.The server part is where the document were processed, and the desktop part is
from where we want we will scan the document, on witch one the scanner is connected.The scan folder should be synchronized between the desktop and the server,
I useSyncthingfor that.On the desktop$python3-mpipinstallscan-to-paperless
$echoPATH=$PATH:~/venv/bin>>~/.bashrc
$echosource<(register-python-argcompletescan)>>~/.bashrc
$echosource<(register-python-argcompletescan-progress-status)>>~/.bashrcCreate the configuration file on<home_config>/scan-to-paperless.yaml(on Linux it's~/.config/scan-to-paperless.yaml), with:# yaml-language-server: $schema=https://raw.githubusercontent.com/sbrunner/scan-to-paperless/master/scan_to_paperless/config_schema.jsonscan_folder:/home/sbrunner/Paperless/scan/scanimage_arguments:# Additional argument passed to the scanimage command---device=...# Use `scanimage --list` to get the possible values---format=png---mode=color---resolution=300default_args:auto_mask:{}auto_cut:{}run_pngquant:truecut_white:200# cut the near white color to have a uniform backgrounddpi:300# Not necessary if the scanner generate a tiff filetesseract_lang:fra+eng# The used languages for the OCRFull config documentationOn the NASThe Docker support is required, Personally I use aSynology DiskStation DS918+,
and you can get the *.syno.json files to configure your Docker services.Otherwise, use:SCAN_FOLDER=<scan_folder>CONSUME_FOLDER=<consume_folder>
dockerrun--name=scan-to-paperless--restart=unless-stopped--detach\--volume=${SCAN_FOLDER}:/source\--volume=${CONSUME_FOLDER}:/destination\sbrunner/scan-to-paperlessYou can set the environment variablePROGRESStoTRUEto get all the intermediate images.To stop run:dockerstopscan-to-paperless
dockerrmscan-to-paperlessRepertory linkYou should find a way to synchronize or using sharing to link the scan folder on your desktop and on your NAS.You should also link to consume folder topaperless-ngxprobably just by using the same folder.UsageUse thescancommand to import your document, to scan your documents.The document is transferred to your NAS (I useSyncthing).The documents will be processed on the NAS.Usescan-process-statusto know the status of your documents.Validate your documents.If your happy with that remove theREMOVE_TO_CONTINUEfile.
(To restart the process remove one of the generated images, to cancel the job just remove the folder).The process will continue his job and import the document inpaperless-ngx.Job config fileIn theconfig.yamlfile present in the document folder, you can find some information generated during
the processing and some can be modified.E.g. you can modify an image angle to fix the skew, then remove a generated image for force to regenerate
the images.Full job config documentationAdvance featureAdd a maskIf your scanner add some margin around the scanned image it will relay case some issue the skew and the
content detection.To solve that you can add a black and white image namedmask.pngin the root folder and draw in black the
part that should not be taken in account.Scan to Paperless is also able to create a mask automatically, to enable is with the default configuration,
just addargsnameauto_maskwith an empty dictionary ({}).See also:The documentationConfiguration note:By default, the optionslower_hsv_colorandupper_hsv_colorselect the page (white).
Yon can also select the scanner background, for that you also should set the optioninverse_masktotrueand the optionde_noise_morphologytofalse.Mask the imageIf your scanner add some margin around the scanned image you can definitively mask them.To solve that you can add a black and white image namedcut.pngin the root folder and draw in black the
part that should not be taken in account.Scan to Paperless is also able to create a mask automatically, to enable is with the default configuration,
just addargsnameauto_cutwith an empty dictionary ({}).See also:The documentationDouble sized scanningPour your sheets on the Automatic Document Feeder.Runscanwith the option--mode=double.Press enter to start scanning the first side of all sheets.Put again all your sheets on the Automatic Document Feeder without turning them.The scan utils will rotate and reorder all the sheets to get a good document.Credit card scanningThe options--append-credit-cardwill append all the sheets vertically to have the booth face of the credit card on the same page.Assisted splitDo your scan as usual with the extra option--assisted-split.After the process do his first pass you will have images with lines and numbers.
The lines represent the detected potential split of the image, the length indicate the strength of the detection.
In your config you will have something like:assisted_split:-destinations:-4# Page number of the left part of the image-1# Same for the right page of the imageimage:image-1.png# name of the imagelimits:-margin:0# Margin around the splitname:0# Number visible on the generated imagevalue:375# The position of the split (can be manually edited)vertical:true# Will split the image vertically-...source:/source/975468/7-assisted-split/image-1.png-...Edit your config file, you should have one more destination than the limits.
If you put destination like that: 2.1, it means that it will be the first part of the page 2 and the 2.2 will be the second part.Delete the fileREMOVE_TO_CONTINUE.After the process do his first pass you will have the final generated images.If it's OK delete the fileREMOVE_TO_CONTINUE.The scan modes configurationFirst of all thescanimagecommand and arguments can be configured with thescanimageandscanimage_argumentssoptions in the configuration file (~/.config/scan-to-paperless.yaml).In this file there is also amodessection that can configure each modes.See also:The documentationExtends an existing configurationTo create thepresetconfiguration file it can be useful to extends an existing configuration.
For that you can use theextends(andmerge_strategies) option in the configuration file.See also:The documentationServer configurationEnvironment variable:SCAN_SOURCE_FOLDER: The main input folder for the scan process.SCAN_CODES_FOLDER: The input folder for the codes (QR code ad Barcode) detection and add a new page.SCAN_FINAL_FOLDER: The final folder for the scan process.SCAN_CODES_DPI: The used DPI to decode the codes.SCAN_CODES_PDF_DPI: The used PDF DPI to create the codes document.SCAN_CODES_FONT_NAME: The used font of code number.SCAN_CODES_FONT_SIZE: The used font size of code number.SCAN_CODES_MARGIN_TOP: The top margin of code number.SCAN_CODES_MARGIN_LEFT:The left margin of code number.TIME: Print the elapsed time.PROGRESS: Save some intermediate files, don't clean the folder at the end.