--- /dev/null
+#!/usr/bin/env zsh
+# Original ps2pdf is just a trivial caller to gs too.
+# That ones is lossless, tries to be closer to PDF/A-1.
+# It also copies Producer metainformation tag to Creator,
+# removes all empty metainformation fields, removed fields
+# with uuid:s, removes Format (that is application/pdf).
+
+set -e
+opts=(
+ -dQUIET
+ -dBATCH
+ -dNOPAUSE
+ -dSAFER
+ -sDEVICE=pdfwrite
+ -dPDFSETTINGS=/default
+ -dPDFA=1
+ -dCompatibilityLevel=1.4
+ -dPDFACompatibilityPolicy=3 # that will skip some errors about XMP
+ -dAutoRotatePages=/None
+ -dOptimize=true
+ -sColorConversionStrategy=RGB # advised for PDF/A
+ -sProcessColorModel=DeviceRGB # advised for PDF/A
+ -dAutoFilterColorImages=false
+ -dAutoFilterGrayImages=false
+ -dAutoFilterMonoImages=false
+ -dColorImageFilter=/FlateEncode
+ -dGrayImageFilter=/FlateEncode
+ -dMonoImageFilter=/FlateEncode
+ -sOutputFile="$1".pdf
+)
+gs ${=opts} $1
+
+toremove=(Format)
+exiftool $1.pdf | while read l ; do
+ f=${${(s/:/)l}[1]:gs/ //}
+ [[ "$l" =~ ": " ]] || toremove=($f $toremove)
+ [[ "$l" =~ ": uuid:" ]] && toremove=($f $toremove)
+done
+for i ({1..${#toremove}}) toremove[$i]=-${toremove[$i]}=
+exiftool -zip -overwrite_original -quiet \
+ -tagsFromFile $1 -Producer\>Creator \
+ ${=toremove} $1.pdf
+qpdf --linearize --compress-streams=y $1.pdf $1.pdf.pdf
+mv $1.pdf.pdf $1.pdf