PDF ファイルをいじれる十徳ナイフ的なプログラム
ドキュメント: https://ghostscript.readthedocs.io/en/latest/Use.html

PDF サイズを小さくしたい

gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -dColorImageDownsampleThreshold=2 -dColorImageDownsampleType=/Bicubic -dPDFSETTINGS=/printer -sOutputFile=output.pdf input1.pdf input2.pdf (……入力PDFを複数指定できる)

-dPDFSETTINGS=/printer はプリンタ品質で出力することを指定する。詳しくは 公式ドキュメント にあるが、ほかには screen ebook printer prepress が指定できる
さらにオプションで品質を制御できる。例えば上の例では以下を設定している

  • -dColorImageDownsampleThreshold=1.5: 数字によって画像の綺麗さを変えてサイズを圧縮できる
  • -dColorImageDownsampleType=/Bicubic: 画像のダウンサンプルに使う手法

PDF/A にしたい

-dPDFA でできる
さらにいくつかのオプションを指定して以下のようにするのがよい

gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -dPDFA=3 -sColorConversionStrategy=RGB -dEmbedAllFonts=true -dPDFACompatibilityPolicy=3 -sOutputFile=output.pdf input1.pdf input2.pdf ...