A powerful command-line tool for adding password protection to PDF files.
- Add password protection to PDF files
- Interactive CLI with file browser
- Automatic dependency detection and installation
- Cross-platform support (Linux, macOS, Windows)
- Comprehensive error handling
- Preserves PDF quality and text selectability
This tool requires qpdf to be installed on your system. The CLI will automatically detect if qpdf is missing and offer to install it for you using your system's package manager.
If you prefer to install qpdf manually:
Linux (Debian/Ubuntu):
sudo apt-get install qpdfmacOS (Homebrew):
brew install qpdfWindows (Chocolatey):
choco install qpdfWindows (winget):
winget install qpdf.qpdfFor more installation options, visit: https://qpdf.readthedocs.io/en/stable/installation.html
Install globally to use the command-line tool:
npm install -g lock-pdfOr with pnpm:
pnpm add -g lock-pdfSimply run the command without arguments for an interactive experience:
lock-pdfThis will:
- Open an interactive file browser to select your PDF
- Check if the PDF is already password-protected (warns if so)
- Prompt for the password (with confirmation)
- Ask for the output file path (with a default suggestion)
- Lock the PDF and save it
Provide all arguments directly:
lock-pdf <input-file> <password> [options]Examples:
# Lock a PDF with default output name
lock-pdf document.pdf myPassword123
# Specify custom output path
lock-pdf document.pdf myPassword123 -o protected.pdf
# Using full paths
lock-pdf /path/to/document.pdf myPassword123 -o /path/to/output.pdf-o, --output <path>- Specify the output file path (default: adds "_locked" suffix to input filename)--skip-dependency-check- Skip the qpdf dependency check (not recommended)-V, --version- Output the version number-h, --help- Display help information
This tool uses qpdf, a powerful command-line program for PDF manipulation. When you provide a PDF file:
- The tool validates the input file
- Checks if the PDF is already password-protected (warns if so)
- Uses
qpdfwith the provided password to encrypt the PDF - Saves the password-protected PDF to the specified output path
The original PDF quality, formatting, and text selectability are preserved.
