There are many programs and tools you can use to compress pdf files, I find the GhostScript to work really well in my case.
What is GhostScript
The gs command invokes Ghostscript, an interpreter of Adobe Systems’ PostScript(tm) and Portable Document Format (PDF) languages.
gs reads “files” in sequence and executes them as Ghostscript programs. After doing this, it reads further input from the standard input stream (normally the keyboard), interpreting each line separately and output to an output device.
The interpreter exits gracefully when it encounters the “quit” command (either in a file or from the keyboard), at end-of-file, or at an interrupt signal (such as Control-C at the keyboard).
You can read more about the GS typing in the terminal
Using the Ghost script to compress a PDF file
gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -sNAME=setting -sOutputFile=your_compressed_file_name_here.pdf input_file_name_here.pdf
Using the Gost Script to merge pdf files:
This Ubuntu built in software can be used also to merge pdf files. The following command will merge file1.pdf and file2.pdf in a single file named finished.pdf.
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -dAutoRotatePages=/None -sOutputFile=finished.pdf file1.pdf file2.pdf
gs starts the Ghostscript program. -dBATCH once Ghostscript processes the PDF files, it should exit. If you don't include this option, Ghostscript will just keep running. -dNOPAUSE forces Ghostscript to process each page without pausing for user interaction. -q stops Ghostscript from displaying messages while it works -sDEVICE=pdfwrite tells Ghostscript to use its built-in PDF writer to process the files. -sOutputFile=finished.pdf tells Ghostscript to save the combined PDF file with the specified name. -dAutoRotatePages=/None Acrobat Distiller parameter AutoRotatePages controls the automatic orientation selection algorithm: For instance: -dAutoRotatePages=/None or /All or /PageByPage.
After the merge we can use the first script to reduce its size and protect our file with a password.
Password Protect our PDF file
gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -sNAME=setting -sOwnerPassword=mypassword -sOutputFile=your_protected_file_name.pdf input_file_name_here.pdf