Print a text file to PDF from CLI on Linux

It is nice how modern text editors have that feature to “print” a file to PDF. I wanted to do the same from CLI and after a bit of looking around i’ve found this solution:

sudo apt-get install enscript
enscript lorem.txt -o - | ps2pdf - lorem.pdf

There is also the unoconv, which converts between any document format that OpenOffice understands. It uses OpenOffice’s UNO bindings for non-interactive conversion of documents.
Supported document formats include Open Document Format (.odt), MS Word (.doc), MS Office Open/MS OOXML (.xml), Portable Document Format (.pdf), HTML, XHTML, RTF, Docbook (.xml), and more.


Converts between different document formats that OpenOffice understands
OpenOffice can export to about 100 different document formats
Can be used for batch processing
Combines with asciidoc and docbook2odf/xhtml2odt to create PDF or Word (.doc) files
Can apply custom style templates during conversion (to enforce corporate identity)
Autostarts OpenOffice for processing if necessary
Can be used in a client/server environment to process documents centrally
Can influence OpenOffice filters during import and export
Supports OpenOffice on Linux, Windows and MacOSX

1 reply on “Print a text file to PDF from CLI on Linux”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.