Skip to main content

Python script to make documents look like they were scanned.

Project description

look-like-scanned

Pylint PyTest license Contributions Welcome made-with-python

  • Python script to make documents look like they were scanned.

  • Local, Private, Secure, Open-Source and Transparent!

  • Converts every page of a given PDF file into an image-based page and applies random askew and brightness (very mild) effects to simulate the appearance of scanned documents.

  • The resulting pages are then combined back into an Output PDF file.

  • There are options to combine / convert image files into PDF as well.

  • Output PDF files are saved in the same folder with a suffix "File_Name_output.pdf"

Installation

Install from the Python Package Index (PyPI)

pip install look-like-scanned

Or to install latest version from GitHub

git clone https://github.com/navchandar/look-like-scanned.git
cd look-like-scanned
pip install poetry
poetry install
pip install .

Verify Installation:

# Print help message and usage options available
scanner -h

Usage

This package uses PIL and pypdfium2 to convert and manipulate image and pdf objects.

This is extended to provide a command-line interface (CLI) for easy usage.

# Convert all pdf files in folder to scanned pdf
scanner -i .\tests
scanner -i .\tests -f "pdf"

# Convert all pdf files in folder to scanned pdf, set contrast, sharpness and brightness factors
scanner -i .\tests -c 2 -sh 10 -br 2

# Convert all pdf files in folder to scanned without askew
scanner -i .\tests -a no

# Convert specific pdf file in folder to scanned pdf
scanner -i .\tests -f "test.pdf"

# Convert all jpg, jpeg, png, webp files in folder to one pdf file
scanner -i .\tests -f "image"

# Convert all image files in folder in the order of file names
scanner -i .\tests -f "image" -s "name"

# Convert all png files in folder to pdf with 100% quality to one pdf file
scanner -i .\tests -f "png" -q 100

# Convert specific jpg file in folder to pdf with 75% quality to one pdf file
scanner -i .\tests -f "JPG_Test.jpg" -q 75

# Convert all PDF files including sub folders
scanner -i .\tests -f "pdf" -r yes

# Convert all Images including sub folders into one PDF
scanner -i .\tests -f "image" -r yes

# Convert all PDF files including sub folders and save in black & white format
scanner -i .\tests -f "pdf" -r yes -b yes

# Convert all png files including sub folders and make it a little blurry
scanner -i .\tests -f "png" -r yes -b yes -l yes

Arguments

These are the command-line arguments accepted:

  • -i, --input_folder : Specifies the input folder to read files from and convert. The default value is the current directory.

    • Example: -i /path/to/files or -i C:\files\documents
  • -f, --file_type_or_name : Specifies the file types to process or the file name to convert. The default value is "pdf" to convert all pdf files in the given input folder.

    • Example: -f pdf or -f image.jpg or -f image
  • -q, --file_quality : Specifies the quality of the converted output files. The value must be between 50 and 100. The default value is 95.

    • Example: -q 90
  • -a, --askew : Controls whether to make the output documents slightly askew or slightly tilted. Accepted values are "yes" or "no". The default value is "yes".

    • Example: -a yes or --askew no
  • -b, --black_and_white : Controls whether to save output documents in black and white format (to make it look like a photocopy) . Accepted values are "yes" or "no". The default value is "no".

    • Example: -b yes or --black_and_white no
  • -l, --blur : Controls whether to make the output a little bit blurry. Accepted values are "yes" or "no". The default value is "no".

    • Example: -l yes or --blur no
  • -c, --contrast : Controls contrast factor of the image. A factor of 0.0 gives a solid gray image. A factor of 1.0 gives the original image. Greater values increase the contrast of the image. The default value is 1.

    • Example: -c 2
  • -sh, --sharpness : Controls sharpness factor of the image. A factor of 0.0 gives a blurred image. A factor of 1.0 gives the original image. Greater values increase the sharpness of the image. The default value is 1.

    • Example: -sh 2
  • -br, --brightness : Controls brightness factor of the image. A factor of 0.0 gives a black image. A factor of 1.0 gives the original image. Greater values increase the brightness of the image. The default value is 1.

    • Example: -br 2
  • -r, --recurse : Allows scripts to find all matching files including subdirectories. Accepted values are "yes" or "no". The default value is "yes".

    • Example: -r yes or --recurse no
  • -s, --sort_by : Allows scripts to sort the files based on name, creation time or modified time. Accepted values are "name", "ctime", "mtime", "none". The default value is "name". If "none" is selected, then the default order of files returned by the OS is used for document conversion.

    • Example: -s name or --sort_by none

❗❗ Note: ❗❗

  • The supported file types are: ".jpg", ".png", ".jpeg", ".webp", ".pdf".

  • The output PDF file size will be bigger than the input file because the pages are stored in image format.

  • Bookmarks / Links / Metadata will be removed when saving the output file.

  • Transparency will be removed from png files when converting to pdf.

  • Password protected PDF files are not yet supported.

  • Youtube: How to Insert a Signature on a PDF File

License

MIT license

Authors

Support This Project

Paypal Badge BuymeCoffee Badge Ko-Fi Badge

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

look_like_scanned-1.0.6.tar.gz (20.2 kB view details)

Uploaded Source

Built Distribution

look_like_scanned-1.0.6-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

Details for the file look_like_scanned-1.0.6.tar.gz.

File metadata

  • Download URL: look_like_scanned-1.0.6.tar.gz
  • Upload date:
  • Size: 20.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for look_like_scanned-1.0.6.tar.gz
Algorithm Hash digest
SHA256 e05787295d727ea5ba0e1a805f157e200aee3f9a073271a08602af3227d6e58a
MD5 cde8e877e2dba153d2621636e8f17cf7
BLAKE2b-256 7a654d6900a9e0aafa8dfd36c3af4481e7c6b78a325f7ba9bca97f97d8bf63fd

See more details on using hashes here.

File details

Details for the file look_like_scanned-1.0.6-py3-none-any.whl.

File metadata

File hashes

Hashes for look_like_scanned-1.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 a2c3a319b5aea80153d978eab3e2a9ae512bf112ea8e9d9bce932cbb1c533bf7
MD5 a3ce4a49d719f02924f728e964004c6c
BLAKE2b-256 4458a8f5f44346e811e748beed091cb31dcd48fd143bb2080d306c9be2e795f8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page