How to convert a text file to PDF format on Linux

Last updated on July 24, 2020 by Dan Nanni

Question: I want to convert a plain text file into a PDF document. Is there an easy way to convert a text file to a PDF file from the command line on Linux?

When you have a bunch of text documents to maintain, there are advantages in converting them into PDF format. For example, PDF is good for printing because PDF documents have pre-defined layout. Besides, with PDF format, there is less risk hat the documents are accidentally modified.

To convert a text file to PDF format, you can follow two-step procedures.


First, you need to install two prerequisite packages.

For Debian, Ubuntu or Linux Mint:

$ sudo apt-get install enscript ghostscript

For Fedora, CentOS or RHEL:

$ sudo yum install enscript ghostscript

For Arch Linux:

$ sudo pacman -S enscript ghostscript

Convert a Text File to PDF Format

Once all prerequisites are installed, follow these two steps to generate a PDF file from a text file.

First, convert a text file to Postscript format by using enscript command-line tool.

$ enscript -p input.txt

Finally convert the generated postscript file to a PDF file.

$ ps2pdf output.pdf

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal or credit card

Please note that this article is published by under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at as the original source.

Xmodulo © 2021 ‒ AboutWrite for UsFeed ‒ Powered by DigitalOcean