Skip to content

Instantly share code, notes, and snippets.

Last active November 9, 2023 19:03
Star You must be signed in to star a gist
What would you like to do?
Make a pdf look scanned using ImageMagick
# use ImageMagick convert
# the order is important. the density argument applies to input.pdf and resize and rotate to output.pdf
convert -density 90 input.pdf -rotate 0.5 -attenuate 0.2 +noise Multiplicative -colorspace Gray output.pdf
Copy link

Pezmc commented Feb 17, 2021

I've improved upon this script slightly (having used it for a while now):

  • by splitting the PDF into separate pages per file
  • applying slightly different rotations to each page
  • recombining the files
  • support for macOS automator quick actions
  • Fixing the noise so it appears across the document


Copy link

vwkd commented Sep 24, 2021

Thanks @Pezmc. To have the noise only at the edges instead of across the whole document is a feature IMO, and also keeps the file size much smaller. Unfortunately, I couldn't figure out how to get your script to use noise only at the edges.

I ended up modifyng the original script using the higher density to make the output sharper. Got to keep up with the increasing quality of the scanners in the 3 years since then. 😉

convert -density 130 input.pdf -rotate 0.2 -attenuate 0.2 +noise Multiplicative -colorspace Gray output.pdf

Copy link

For those on Windows make sure to install Ghostscript as well or else you'll get errors like

convert: FailedToExecuteCommand `"gswin32c.exe" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r150x150"  "-sOutputFile=C:/Users/TURKEY~1/AppData/Local/Temp/magick-9420wtSmlrXSBcfh%d" "-fC:/Users/TURKEY~1/AppData/Local/Temp/magick-9420IJ2RKxHzcTQf" "-fC:/Users/TURKEY~1/AppData/Local/Temp/magick-9420t7VINjcK97Pq"' (The system cannot find the file specified.
) @ error/delegate.c/ExternalDelegateCommand/475.
convert: PDFDelegateFailed `The system cannot find the file specified.
' @ error/pdf.c/ReadPDFImage/662.

Copy link

restyler commented Jan 3, 2022

thank you! I have used some of these commands to build which not only applies scanner effect, but also allows to insert an image of signature or draw a signature.
My observations regarding -density parameter: 200 is good enough in most cases, while 300 gives ultimate quality - but the build time get catastrophically slow..

Copy link


Copy link

Thank you!
I used zenity to add graphical input and output prompts:
convert -density 150 "$(zenity --file-selection --title="Select Input File" --file-filter=*[PpDdFf])" -rotate "$([ $((RANDOM % 2)) -eq 1 ] && echo -)0.$(($RANDOM % 4 + 5))" -attenuate 0.4 +noise Multiplicative -attenuate 0.03 +noise Multiplicative -sharpen 0x1.0 -colorspace Gray "$(zenity --file-selection --save --title="Select Output File" --filename ".pdf")"

Can also be found here as a .desktop file, so the script can be started from the starter on Linux machines:

Copy link


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment