Search code examples
linuxwindowsubuntupdfenscript

PDF generated in Linux does not open in Windows - using enscript


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!


Solution

  • 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.