Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Converts given source code into pdf file with syntax highlighting, line numbers and much more

Project Description


Convert various source code into pdf file with syntax highlighting and many more features


Click above for demo



Build from source

git clone
cd code2pdf
python install


Using pip

pip install code2pdf


A. As console app


code2pdf -h


code2pdf [-h] [-l] [-s SIZE] [-S NAME] [-v] filename [outputfile]


positional arguments:
  filename              absolute path of the python file
  outputfile            absolute path of the output pdf file

optional arguments:
  -h, --help            show this help message and exit
  -l, --linenos         include line numbers.
  -s SIZE, --size SIZE  PDF size. A2,A3,A4,A5 etc
  -S NAME, --style NAME
                        the style name for highlighting. Eg. emacs, vim style etc.
  -v, --version         show program's version number and exit

Available style types are

  • [x] autumn
  • [x] borland
  • [x] bw
  • [x] colorful
  • [x] default
  • [x] emacs
  • [x] friendly
  • [x] fruity
  • [x] igor
  • [x] manni
  • [x] monokai
  • [x] murphy
  • [x] native
  • [x] paraiso-dark
  • [x] paraiso-light
  • [x] pastie
  • [x] perldoc
  • [x] rrt
  • [x] tango
  • [x] trac
  • [x] vim
  • [x] vs
  • [x] xcode


code2pdf -l -s a3 -S emacs ~/Code2Pdf/Code2pdf/ ~/Code2Pdf/Demo/demo.pdf

To see the demo for above check Demo/ in github repo

B. As module

from Code2pdf.code2pdf import Code2pdf
ifile,ofile,size = "", "test.pdf", "A4"
pdf = Code2pdf(ifile, ofile, size)  # create the Code2pdf object
pdf.init_print()    # call print method to print pdf


Have an idea to make it better? Go ahead! I will be happy to see a pull request from you! :blush: While creating a PR, please update the Contributor section too( see below ).


Release History

Release History

This version
History Node


History Node


History Node


Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
Code2pdf-1.0.0.tar.gz (4.8 kB) Copy SHA256 Checksum SHA256 Source Apr 6, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting