Print PDF from any Linux program

On Linux, the CUPS PDF program saves printed PDFs to the ~/PDF directory from any program.

apt install printer-driver-cups-pdf
# or
dnf install cups-pdf

# then
systemctl restart cups

Verify a PDF printer is visible:

lpstat -p -d

The PDF output directory can be configured by editing the “Out” directory in /etc/cups/cups-pdf.conf

Higher quality PDF might be obtained by using the PDF print options in the specific program, if available.

LibreOffice PDF Conversion

Alternatively, LibreOffice can print compatible documents to PDF directly from the command line in headless mode like:

soffice --headless --convert-to pdf file.docx

Libreoffice can be installed like

apt install libreoffice-common

Related: convert image stack to PDF