Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing python code to PDF [closed]

I have to print to PDF a discrete amount of python script. The code should be included as text, rather than image, as it must be checked by an anti-plagiarism mechanism (I do not have to take care of this, it is just requested that the pdf is not made from an image, that's all). It is also necessary to have syntax highlighting.

Do you have any suggestion regarding a specific tool for this?

like image 526
papafe Avatar asked Dec 05 '13 22:12

papafe


1 Answers

For the anti-plagiarism part, I can't help you. For printing a py script with syntax highlighting, a traditional tool is enscript:

enscript -E -q -Z -p - -f Courier10 readmaya.py | ps2pdf - out.pdf

Here, enscript does the syntax highlighting and produces postscript. You could use any of several possible tools for the second step of converting postscript to pdf. I have shown here ps2pdf which is from the ghostscript package.

Installation

On a Debian- or Unbuntu-like system, enscript can be installed with:

apt-get install enscript

On a Debian- or Unbuntu-like system, ps2pdf is part of the ghostscript package which is likely already installed. If it isn't. run:

apt-get install ghostscript
like image 137
John1024 Avatar answered Oct 15 '22 01:10

John1024