Recent 2023 Ghostscript versions do not support -sDEVICE=psmono
option which was an easy way to convert any PDF to first monochrome (black and white, not grayscale) postscript file and then back to PDF using -sDEVICE=pdfwrite
option. New Ghostscript has monochrome output devices like bmpmono
and pngmono
, but it seems that Ghostscript is unable to create PDFs from those files any longer.
Artiflex, distributor of the Ghostscript has another open source tool MuPDF, that can do this fairly well. Here is my example of a Windows 10 batch file, which is able to convert any PDF to a smaller monochrome PDF by just dragging and dropping the large file on top of this batch file. This batch file requires mupdf-1.21.0-windows.zip
to be unzipped (no installation required) to the same folder where this batch file and PDF are. It will automatically take a backup copy of the original file, so that nothing is lost during the process. It will create very compact 300dpi monochrome multi page PDFs. Save the code into file and name it e.g. DropHereToConvert.bat
.
@echo off
rem === Separate the file and folder names of the dropped file (%1) to two different string variables, and replace the empty spaces in filename with underlines ===
set filename=%1
set filename=%filename: =_%
for %%A in ("%filename%") do (
set Folder=%%~dpA
set Name=%%~nA )
echo.Folder is: %Folder%
echo.Name is: %Name%
rem
rem === Make a backup copy of the dropped PDF file to -- Name_original.pdf -- and remove the space from the end of -- Name -- variable ===
copy %1 "%Name: =_%original.pdf"
rem
rem === Copy the dropped file to a temporary file for -- mutool.exe -- to process ===
copy %1 oldTempFile.pdf
rem
rem === Use -- mutool.exe -- that must be located in the same folder with the processed PDF-file and this batch file to create individual monochrome PBM-type images from each page with following parameters:
rem page%%3d.pbm -- names the files leading zeroes: page001.pbm, page002.pbm etc.,
rem -G7 -- uses gamma value 7 to darken thin lines so that they don't fade away
rem -cm -- makes the output monochrome
rem -A9 -- no anti-aliasing
rem -r300 -- defines the dpi-quality of the image files to be 300 dpi ===
mutool.exe draw -o page%%3d.pbm -G7 -A9 -cm -r300 oldTempFile.pdf
echo Pbm files created
rem
rem === Create a list of the pbm filenames into a file -- listOfFiles2.lst -- for creating a single PDF-file containing all individual pages created earlier ===
rem
rem === First list all PBM-files to a filename list where the names are separated line breaks, using -- dir -- command which will not break batch file, even if there are empty spaces in the filename (this happens with if -- for -- is used at this stage) ===
dir /b *.pbm > listOfFiles.lst
rem
rem === Then remove the line breaks from the this list to create a single string that contains all filenames separated only by spaces, because mutool.exe requires that kind of input. Add an empty space at the end of each filename with -- "%%i " --, because listing with -- dir -- removes them ===
for /f "usebackqdelims=" %%i in (listOfFiles.lst) do @<nul set /p="%%i ">>listOfFiles2.lst
rem
rem === Store this single line list into -- %build% -- variable to be used with mutools.exe as a parameter ===
set /p Build=<listOfFiles2.lst
echo Single line list: %Build%
rem
rem === Use this single line list to create a single monochrome PDF-file with the same file name that was dropped on this batch file. This file contains all monochrome PBM-images in compressed format, and with a filename where all empty spaces are replaced by the underlines. Original dropped file was saved earlier with -- "_original" -- added to the end of the filename. NOTE that -- mutool.exe -- output parameters don't currently specify the paper size or scaling, so in order to print the files one must use -- Fit to page -- or scaling it exactly 32% ===
mutool.exe convert -o "%Name: =%.pdf" -Ocompress-images %Build%
echo Monochrome PDF created
rem
rem === Delete all temporary files that were created during the process ===
echo Deleting the temporary files...
del listOfFiles.lst
del listOfFiles2.lst
del *.pbm
del oldTempFile.pdf