0

My professor and I both use Linux to run some CFD codes, but both our PDF outputs from enscript do not open on Windows (which the TA uses to correct my assignment). The pdf's open without a problem in Linux however (my prof uses native Fedora and I use Ubuntu 16.04 on a virtual machine.

Here is the command line that I used:

enscript --color --pretty-print=cpp Assignment5.cpp --line-numbers -p Assignment5.pdf

And I got this error when trying to open the PDF in windows:

Error window

Thanks!

plinth
  • 48,267
  • 11
  • 78
  • 120
  • Are you sure you did not simply accidentally break the binary PDF file while transferring the PDF from your Linux machines to Windows, e.g. by accidentally treating the PDF as text? – mkl Mar 29 '17 at 19:00
  • @mkl I uploaded the file to google drive from Linux and downloaded it in Windows. The file my professor sent to me was sent as an attachment and I downloaded it as I always download my files. – John Charbonneau Mar 29 '17 at 19:07
  • Can you share it for analysis? – mkl Mar 29 '17 at 19:15
  • Check this out @mkl https://expirebox.com/download/2cb962e7bd904124b165c8f2db57aa69.html – John Charbonneau Mar 29 '17 at 21:15
  • If you do get it running, please keep in mind I am a beginner in C++ :) haha @mkl – John Charbonneau Mar 29 '17 at 21:18
  • Ok, I just tried to download the file from android (which also is based on Linux) but here, too, the pdf viewer complains. I'll look at it later in office. – mkl Mar 30 '17 at 04:29
  • Ok, I just inspected the file: It is not a PDF at all, it is a postscript file! – mkl Mar 30 '17 at 08:08
  • 1
    I saw your answer and that solved my problem! Thank you very much @mkl, I appreciate the help! – John Charbonneau Mar 30 '17 at 13:48

1 Answers1

0

enscript actually creates a postscript file, not a PDF file. Most likely the PDF viewer used on the Linux systems in question also can display postscript files and, therefore, did not complain while the PDF viewer used on Windows can not. To actually create a PDF run ps2pdf on the enscript output.

On enscript

enscript (at least the GNU version) does not output PDF but a choice of other formats:

GNU Enscript converts ASCII files to PostScript, HTML, or RTF and stores generated output to a file or sends it directly to the printer.

According to its man page the actual output format is selected using the -W / --language option:

-W [lang], --language[=lang]
               Generate output for the language lang.  The possible values for
               lang are:

               PostScript
                       generate PostScript (default)

               html    generate HTML

               overstrike
                       generate overstrikes (line printers, less)

               rtf     generate RTF (Rich Text Format)

               ansi    generate ANSI terminal control codes

Your enscript call does not include this option. Thus, by default postscript is generated.

How to create PDF

A common tool on Linux systems is ps2pdf which you can use to generate a PDF from your enscript postscript output:

ps2pdf - Convert PostScript to PDF using ghostscript

ps2pdf12 - Convert PostScript to PDF 1.2 (Acrobat 3-and-later compatible) using ghostscript

ps2pdf13 - Convert PostScript to PDF 1.3 (Acrobat 4-and-later compatible) using ghostscript

According to its man page it can be called with merely the source postscript and target PDF file names on the command line:

ps2pdf  [options...] {input.[e]ps|-} [output.pdf|-]
ps2pdf12  [options...] {input.[e]ps|-} [output.pdf|-]
ps2pdf13  [options...] {input.[e]ps|-} [output.pdf|-]

You may have yet to install ghostscript to run it.

Community
  • 1
  • 1
mkl
  • 90,588
  • 15
  • 125
  • 265