Encrypting PDF files with free command line tools
PDF files can be encrypted using command line tools QPDF and PDFtk. These are available for Windows and Linux.
Description from QPDF:
This is the QPDF package. QPDF is a command-line tool and C++ library that performs content-preserving transformations on PDF files. It supports linearization, encryption, and numerous other features. It can also be used for splitting and merging files, creating PDF files (but you have to supply all the content yourself), and inspecting files for study or analysis. QPDF does not render PDFs or perform text extraction, and it does not contain higher-level interfaces for working with page contents. It is a low-level tool for working with the structure of PDF files and can be a valuable tool for anyone who wants to do programmatic or command-line-based manipulation of PDF files.
QPDF supports 40-bit, 128-bit and 256-bit encryption and the key length must be specified. The examples below show 256-bit encryption.
qpdf --encrypt PASSWORD PASSWORD 256 -- input.pdf output.pdf
--modify=none restrictions to block users from modifying the file.
qpdf --encrypt PASSWORD PASSWORD 256 --modify=none -- input.pdf output.pdf
The format for the encryption option is:
--encrypt user-password owner-password key-length [ restrictions ] --
Description from PDF Labs:
PDFtk Free is our friendly graphical tool for quickly merging and splitting PDF documents and pages. It is free to use for as long as you like.
PDFtk supports only 40-bit and 128-bit (default) encryption.
pdftk input.pdf output output.pdf user_pw PASSWORD