9

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
Tim
  • 98,580
  • 191
  • 570
  • 977

1 Answers1

10

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

or

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 '18 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 '18 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 '18 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 '18 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 '18 at 19:05
  • My pdf printer is named `PDF`. `enscript -B --printer=PDF code/bloom.c -p myfile.pdf` and `enscript -B -P PDF code/bloom.c -p myfile.pdf` and `enscript -B -PPDF code/bloom.c -p myfile.pdf` all create ps file not pdf file. Not sure why that is and what you mean. – Tim Sep 20 '18 at 19:34
  • How shall I verify the name of the PDF printer? `-PPDF` without `-o` or `-p` creates pdf, so I don't think `-PPDF` is wrong. – Tim Sep 20 '18 at 19:40
  • `system default destination: PDF`. `-PPDF` without `-o` or `-p` creates pdf under `~/PDF/`, so I don't think `-PPDF` is wrong. `-o` or `-p` is the cause, but I don't know why. – Tim Sep 20 '18 at 19:41
  • `-P PDF` and `-PPDF` work the same in my previous comment. – Tim Sep 20 '18 at 19:43