I was wondering why the following generates a ps file not a pdf file? How can I make it generate a pdf file? Thanks.

$ enscript -B -PPDF code/bloom.c -o bloom.pdf 
[ 2 pages * 1 copy ] left in bloom.pdf
$ file bloom.pdf 
bloom.pdf: PostScript document text conforming DSC level 3.0

I have already installed cups-pdf by

sudo apt install cups-pdf
up vote 8 down vote accepted

By default, enscript only makes postscipt file (ps).

Your command line is missing two flags: small -p and capital -P. The command line must be like this:

enscript -B -P <PDF_PRINTER_NAME> code/bloom.c -p myfile.ps

According to enscript manpage

-P name, --printer=name
Spool the output to the printer name.

-p file, --output=file
Leave the output to file file. If the file is `-', enscript sends the output to the standard output stdout.

If a pdf printer in not available in the system, then ghostscript can convert the ps file to pdf file as follows:

sudo apt install ghostscript
ps2pdf myfile.ps myfile.pdf


enscript file -o - | ps2pdf - output.pdf

When pdf printer is default in the system, then something like this command, will output pdf files instead of the ps files:

enscript -2 -r -j --font=Times-Roman11 --word-wrap --mark-wrapped=arrow '%f' && sleep 2 && evince ~/PDF/_stdin_.pdf

- The `%f` designates the filename parameter.    
- The `&& sleep 2 &amp;&amp; evince ~/PDF/_stdin_.pdf` commands will wait two seconds for the print job to finish, then run the Evince PDF viewer to display the file _stdin_.pdf you just generated in the user’s PDF subdirectory.
  • Thanks. Why does -PPDF not make it create pdf file directly? Is it the case on your linux? – Tim Sep 20 at 18:47
  • How would you " set your default Printer in the system to the PDF printer"? Does -PPDF already specify the printer to be the PDF printer? – Tim Sep 20 at 18:51
  • Is there a reliable command which will work in both cases with or without making the PDF printer default? – Tim Sep 20 at 18:56
  • Thanks. Is this your preferred way to convert a text file to a pdf file? What is it if not? – Tim Sep 20 at 18:58
  • May I also ask why enscript -2 -r -j --font=Times-Roman11 --word-wrap --mark-wrapped=arrow code/bloom.c create a pdf file directly? The options have nothing to do with it. I found that -o might be the cause, but don't understand why it is. – Tim Sep 20 at 19:05

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.