How to print a regular file to pdf from command line
Here's a solution that doesn't involve OpenOffice:
sudo apt-get install enscript
enscript my_text_file.txt -o - | ps2pdf - output.pdf
There are more options to enscript
, e.g. -B
to omit the page header. See man enscript
for all of the options.
without installing any of the above mentioned software, one can simply do the following with already installed cupsfilter
:
cupsfilter foo.txt > foo.pdf
(for options etc. please refer to cupsfilter man pages :-) )
THE SIMPLE ENSCRIPT WAY
sudo apt-get install cups-pdf enscript
Then run enscript on your file with the -P switch and the printer description PDF in this case.
enscript -B -PPDF test.txt
A printer with description PDF was created when you installed cups-pdf, when you use enscript with that printer your document will be sent to the PDF printer and will be printed to file, created as .pdf in your /home/PDF directory, the command above will print the text file test.txt as a pdf in the PDF directory.
USING UNOCONV
sudo apt-get install unoconv
You can use unoconv in standalone mode, this means that in absence of an OpenOffice listener, it will start its own:
In the directory where your file is located run:
unoconv -f pdf test.txt
this will create a nice looking pdf of test.txt. in the current directory