Closed baldvin-kovacs closed 1 year ago
I got the same error initially. I was able to get one step further by installing Ghostscript:
brew install gs
That just moved the goalpost to a different Ghostscript related error.
I ended up using a simple bash script to shrink some PDFs. It's far inferior to pdfsizeopt for image compression, but works good enough until I sort out the MacOS issues.
#!/bin/bash
#
# optpdf file.pdf
# This script will attempt to optimize the given pdf
file="$1"
filebase="$(basename "$file" .pdf)"
optfile="/tmp/$$-${filebase}_opt.pdf"
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH \
-sOutputFile="${optfile}" "${file}"
if [ $? == '0' ]; then
optsize=$(stat -f "%z" "${optfile}")
orgsize=$(stat -f "%z" "${file}")
if [ "${optsize}" -eq 0 ]; then
echo "No output! Keeping original"
rm -f "${optfile}"
exit;
fi
if [ ${optsize} -ge ${orgsize} ]; then
echo "Didn't make it smaller! Keeping original"
rm -f "${optfile}"
exit;
fi
bytesSaved=$(expr $orgsize - $optsize)
percent=$(expr $optsize '*' 100 / $orgsize)
echo Saving $bytesSaved bytes \(now ${percent}% of old\)
rm "${file}"
mv "${optfile}" "${file}"
fi
I had the same problem. I managed to get it to work with the following steps:
brew install gs jbig2enc qpdf
sam2p
and did chmod +x sam2p
from the terminal to turn the file into an executable binary. Then try to run it as ./sam2p
, and do not move it to the bin when Mac OS X wants you to do that. Then go into the Mac OSX security settings and choose 'allow anyway', such that the file can now be run.As a temporary workaround, does pdfsizeopt work for you with Docker (instructions here: https://github.com/pts/pdfsizeopt) on macOS?
FYI pdfsizeopt doesn't work (for some PDF inputs) with the latest version of Ghostscript, so brew install gs
is not a universal workaround. You also have to specify pdfsizeopt --do-optimize-fonts=no
.
FYI No need for brew install jbig2enc
, here is how to compile the jbig2 tool used by pdfsizeopt for amd64 macOS: https://github.com/pts/pdfsizeopt-jbig2/blob/master/c-darwinc64.sh
FYI The qpdf exectuable for i386 macOS was built with https://github.com/pts/pts-qpdf/blob/master/c-darwinc32.sh . There is no am64 equivalent yet, but probably it's not too hard to create one.
@pts I was able to use Docker but the install was too big for long term use. The recommendation to avoid font optimization seemed to be the missing piece. It's working for now.
This has been fixed recently (see https://github.com/pts/pdfsizeopt/issues/158 for details). Please follow the updated Installation instructions and usage on macOS section in https://github.com/pts/pdfsizeopt.
I executed the MacOS install procedure, and the test failed: