We use pdftk here, pdftk stands for PDF toolkits, is a cross-platform tool for manipulating PDF files.
How to install pdftk?
$ sudo pkg install pdftk # on FreeBSD $ sudo apt-get install pdftk # on Debian / Ubuntu based GNU/Linux
How to compress PDF via pdftk?
$ pdftk input.pdf output output.pdf compress
You can also decompress by replacing ‘compress’ keyword with ‘uncompress’
$ pdftk input.pdf output output.pdf uncompress
That’s all. Notes that the compression usually works with images only, may not work on the file only contains text and simple shapes.