Cooking with DOS: Images to PDF
https://blogs.unimelb.edu.au/digitisation-lab/?p=285

=======================
Scripts
=======================
folder2pdf-bw.bat - Convert a folder of images into a 300dpi BW PDF document. Output filename is the name of the source folder.
folder2pdf-bw-loop.bat - Convert subfolders into 300dpi BW PDF documents (non-recursive)
folder2pdf-colour.bat - Convert a folder of images into a 200dpi colour PDF document. Output filename is the name of the source folder.
folder2pdf-colour-loop.bat - Convert subfolders into 3200dpi colour PDF documents (non-recursive)
image2pdf-bw.bat - Convert a single image of into a 300dpi BW PDF document. Output filename is the sames as the input file, saved into a temporary directory.
image2pdf-colour.bat - Convert a single image of into a 200dpi colour PDF document. Output filename is the sames as the input file, saved into a temporary directory.
pdf-compress-compare.bat - Convert a single image into multiple single page PDFs with different compression settings. This is intended to help you choose your preferred compression settings.


========================
Command line and tweaks
========================

Full command line for the BW conversion. Double percent signs are required to correctly encode them when run as a batch file.

magick %%a -auto-orient -auto-level -resize 3500x3500^> -unsharp 1.5x1+0.7+0.02 -set option:deskew:auto-crop true -deskew 40%% -colorspace gray -lat 30x30-5%%  -shave 1 -threshold 50%% -define connected-components:mean-color=true -define connected-components:area-threshold=12  -connected-components 4 -bordercolor black -border 2 -fuzz 0%% -fill white -draw "color 0,0 floodfill" -depth 1 -compress Group4 c:\temp\files\in\%%~na.pdf

Generic processing
========================

-auto-orient : Rotate the image according to the setting in EXIF:Orientation metadata in the image. Can be removed if this metadata is not present. Rotations in Adobe Bridge use this field. Rotations in IrfanView and Windows Explorer rotate the image and remove this field.

-auto-level : Normalises the RGB channels of the image without any clipping. This can be considered as a basic colour/contrast correction but may produceundesirable results in some circumstances. Use -contrast-stretch if you want to increase the contrast further.

-resize 3500x3500^> : Resize the image to fit within 3500x3500 pixels (for A4 @ 300DPI) only if the image is larger than this. For A4 @ 200DPI use 2340x2340.

-unsharp 1.5x1+0.7+0.02 : Performs a minor sharpening after resizing the image.

-set option:deskew:auto-crop true : Crop the rotated image to compensate for the increase in image size caused by rotation. Set to false to prevent this. Applies to the following deskew command.

-deskew 40%% : deskew the image (default setting) Using smaller numbers reduces the maximum rotation that will be performed. This may be useful if all images are kept relatively straight during capture.

BW processing
========================

-colorspace gray : Process the image as greyscale

-lat 30x30-5%% : Adaptive threshold for an area of 30x30 pixels with an offest of -5%. Increasing the area will retain larger areas of black (if required) but processing will become increasingly slower at values >50. Offset is negative to produce black on white background. Positive offests produce white on a black background. Smaller offest values will reduce the size of gaps in letters where ink is faded but will also increase noise. Typical values are -5% to -15% depending on the quality of the printing.

-threshold 50%% : Force the image to be bitonal but possibly redundant

-depth 1 :Set the bit depth to 2^1 (bitonal BW)

Noise removal
========================

-define connected-components:mean-color=true : Use for noise reduction. Saves a few extra manipulations so just leave it as is.
-define connected-components:area-threshold=12 : Maximum size of particle to remove (area in pixels)
-connected-components 4 :
Border cleanup (nothing to tweak here, leave or delete)

-shave 1 : Reduce the image size by 1 pixel from each edge. (-lat may leave a 1 pixel wide white border around the edge)

-bordercolor black -border 2 : Add a 2 pixel wide black border around the image. This connects any black areas on the edge of the image together

-fuzz 0%% -fill white -draw "color 0,0 floodfill" : Fill all black pixels joined to the top left corner of the image with white.

-shave 1 : Restores the image to its original size

Compression
========================

-compress METHOD : Recommend "Group4" for BW, "JPEG" or "JPEG2000" for colour/greyscale (without the quotes)

-quality NN : Specify the amount of compression for JPEG/JPEG2000 as a percentage of image quality. 1 - 100, smallest to largest file size.