20071126 txt to ps to pdf or how i learned to love enscript - plembo/onemoretech GitHub Wiki

title: txt to ps to pdf, or how I learned to love enscript link: https://onemoretech.wordpress.com/2007/11/26/txt-to-ps-to-pdf-or-how-i-learned-to-love-enscript/ author: lembobro description: post_id: 600 created: 2007/11/26 18:24:36 created_gmt: 2007/11/26 18:24:36 comment_status: open post_name: txt-to-ps-to-pdf-or-how-i-learned-to-love-enscript status: publish post_type: post

txt to ps to pdf, or how I learned to love enscript

One of the things I love about UNIX open source is the availability of free (as in beer) tools to do things you’d pay tens (if not hundreds or thousands) of dollars to do using proprietary tools on Windows. Converting text to postscript and PDF (Adobe Portable Document Format) is one application I wouldn’t do without. While my company spent thousands on software to format invoice files into PDF to be read by the “free” Adobe Reader, I routinely get the same result with GNU enscript and tools like ggv and gpdf. Red Hat’s Cygwin for Windows include all of the programs discussed here, making these techniques cross-platform.

To convert a plain text file to postscript, I use the following command:

enscript -fHelvetica9 --word-wrap --output=file.ps file.txt

This prints the text file to a postscript file that can be read with ggv and other tools. To suppress the header (by default the filename and a timestamp), I use the -B option. To print a custom header I invoke the -b option with the desired text (e.g. -b ‘Resume of Philip M Lembo’).

For a header that includes some text flush to the left margin, and page info flush to the right you can do something like this (make sure to include the “output=” directive!):

enscript -fHelvetica9 -FHelvetica12 -b 'Philip M Lembo||page $% of $='

Converting postscript to PDF is as easy as invoking the ps2pdf utility:

ps2pdf file.ps file.pdf

It’s that easy. Now aren’t you glad you didn’t pay Adobe a gob of money for a site license?

Copyright 2004-2019 Phil Lembo