Skip to content

Instantly share code, notes, and snippets.

@fieri
Forked from scf37/simulate_scanned_PDF.md
Created April 11, 2022 05:13
Show Gist options
  • Save fieri/02d40eaaa733976a2d53f18bea5033c0 to your computer and use it in GitHub Desktop.
Save fieri/02d40eaaa733976a2d53f18bea5033c0 to your computer and use it in GitHub Desktop.
Simulate a scanned PDF with ImageMagick

Simulate a scanned PDF with ImageMagick

  1. Download and install ImageMagick + Convert Module
  2. Execute the following command in the console
$ convert -density 200 INPUT.pdf -rotate 0.3 +noise Multiplicative -format pdf  -quality 85 -compress JPEG -colorspace gray OUTPUT.pdf

Description of the options

Batch-Scripte

Python (2.7)

from __future__ import print_function
import os
import subprocess

input_dir = "Input/"
output_dir = "Output/"

if not os.path.exists(output_dir):
    os.makedirs(output_dir)
for root, dirs, files in os.walk(input_dir):
    for file in files:
        if file.endswith(".pdf"):
            input_filename = os.path.join(root, file)
            print ("Process: " + input_filename)
            p = subprocess.Popen(
              'convert -density 200 '+input_filename+' -rotate 0.3 +noise Multiplicative -format pdf -quality 85 -compress JPEG -colorspace gray '+str(output_dir +  file), shell=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment