Convert given source code into .pdf with syntax highlighting and more features

Overview

Code2pdf 📠

Convert given source code into .pdf with syntax highlighting and more features

Build Status Version Downloads Python
Build Status PyPI version PyPi downloads PyPI

Demo

demo

Installation

Build from source
git clone https://github.com/tushar-rishav/code2pdf.git
cd code2pdf
pip3 install .

Or

Using pip
pip3 install code2pdf

Usage

A. As console app
Help
code2pdf -h
Usage

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

Options
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
  • autumn
  • borland
  • bw
  • colorful
  • default
  • emacs
  • friendly
  • fruity
  • igor
  • manni
  • monokai
  • murphy
  • native
  • paraiso-dark
  • paraiso-light
  • pastie
  • perldoc
  • rrt
  • tango
  • trac
  • vim
  • vs
  • xcode
Example
 code2pdf -l -s a3 -S emacs ~/Code2Pdf/Code2pdf/code2pdf.py ~/Code2Pdf/Demo/demo.pdf

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

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

Contributions

Have an idea to make it better? Go ahead! I will be happy to see a pull request from you! 😊

While creating a PR, please update the Contributor section too( see below ).

Contributor

Christopher Welborn

cclauss

Thommy257

Comments
  • Packaging name problem

    Packaging name problem

    Hello, just installed via pip under anaconda, and tested via command-line.

    The package directory is named Code2pdf (with uppercase C), but init.py import code2pdf.main (with lowercase c).

    (base) pointal@motus:~$ code2pdf -h Traceback (most recent call last): File "/people/pointal/apps/anaconda3/bin/code2pdf", line 7, in from Code2pdf import main File "/people/pointal/apps/anaconda3/lib/python3.7/site-packages/Code2pdf/init.py", line 1, in from code2pdf import main ModuleNotFoundError: No module named 'code2pdf'

    help wanted good first issue 
    opened by lpointal 6
  • Import error with PyQt4.QtGui in Travis

    Import error with PyQt4.QtGui in Travis

    I've been trying to run tests on Travis. For that I need to first have PyQt4.Gui module installed as one of the dependencies. I'am executing install.sh to install PyQt4. One can see that the module has been installed perfectly at travis dist-packages. Sadly, the module isn't available for import. Am I missing something here? (Refer branch - travis_fix)

    help wanted question 
    opened by tushar-rishav 5
  • problem during installation on MacOS

    problem during installation on MacOS

    Hi,

    I installed code2pdf with pip install But when I try it on terminal occurs an error

    Traceback (most recent call last):
      File "/Library/Frameworks/Python.framework/Versions/3.7/bin/code2pdf", line 11, in <module>
        load_entry_point('Code2pdf==1.0.0', 'console_scripts', 'code2pdf')()
      File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pkg_resources/__init__.py", line 484, in load_entry_point
        return get_distribution(dist).load_entry_point(group, name)
      File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pkg_resources/__init__.py", line 2725, in load_entry_point
        return ep.load()
      File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pkg_resources/__init__.py", line 2343, in load
        return self.resolve()
      File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pkg_resources/__init__.py", line 2349, in resolve
        module = __import__(self.module_name, fromlist=['__name__'], level=0)
      File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/Code2pdf/__init__.py", line 1, in <module>
        from code2pdf import main
    ModuleNotFoundError: No module named 'code2pdf'
    
    opened by sank96 3
  • Compatibility with pyqt5?

    Compatibility with pyqt5?

    Hi, I would like to know if there is any possibility to run this program with pyqt5? The latest version of Anaconda is not allowing me to downgrade pyqt without messing the installation up.

    Thanks!

    opened by shohpfizer 2
  • fixed imports so as to work with Python3

    fixed imports so as to work with Python3

    This change only works with Python3. Thus, it might be better to make a branch called python3 and people can clone that branch if they want to use with python3.

    • Changed PyQt4 to PyQt5
    • Changed all the imports
    • Fixed Code2pdf/__init__.py so that it can be imported
    opened by watakandai 1
  • Support for multiple files - input as a file list - using -f flag

    Support for multiple files - input as a file list - using -f flag

    Added -f or --filelist flag that accepts filename to be a file containing list of file names to be converted to pdf format. Usage: code2pdf -f list_of_files where the file list_of_files contains file names of files to be converted to pdf format. Caveats: This will not work if QT pops segfault

    opened by cibinjoseph 1
  • Multiple files, accept stdin, avoid Qt segfaults. Solves Issue #13

    Multiple files, accept stdin, avoid Qt segfaults. Solves Issue #13

    Each file is highlighted separately and the final content is set to the QDocument. This takes care of Issue #13.

    Instead of a filename, - may be used to pipe stdin to Code2Pdf. Stdin can only be read once, but it can be mixed in with other files.

    Putting the QApplication inside of a class method was causing segfaults (reference was lost before Qt could cleanup). Moving the QApplication to the global scope fixed it. The Code2pdf class is now a subclass of QApplication.

    opened by cjwelborn 1
  • Add more tests

    Add more tests

    The current tests doesn't actually tell you anything useful. Please add unit tests. If you fell you can't write unit tests, then you might wanna reconsider the design itself.

    enhancement 
    opened by sananth12 1
  • Support for multiple languages, line numbers.

    Support for multiple languages, line numbers.

    With pygments, several source file types are supported. Html is formatted with optional line numbers before converting to PDF. (The monokai style seems to conflict with line number styles, and needs to be looked at. Possibly file a bug report with pygments)

    Output file name defaults to current directory and inputfile.pdf (replacing the old extension)

    opened by cjwelborn 0
  • No moudle named PyQt4

    No moudle named PyQt4

    I am using macbook pro 13, bigsur 11.4, python3.7, I have installed code2pdf 1.0.0 version I got error no module named PyQt4 with command code2pdf -h, I got requirements with PyQt5, so why is this with PyQt4? (base) [chenzuoli@chenzuolis-MacBook /Users/chenzuoli/PycharmProjects]$code2pdf -h Traceback (most recent call last): File "/Users/chenzuoli/opt/anaconda3/bin/code2pdf", line 5, in <module> from Code2pdf.code2pdf import main File "/Users/chenzuoli/opt/anaconda3/lib/python3.7/site-packages/Code2pdf/code2pdf.py", line 2, in <module> from PyQt4.QtGui import QTextDocument, QPrinter, QApplication ModuleNotFoundError: No module named 'PyQt4'

    opened by chenzuoli 2
  • No moudle named PyQt4

    No moudle named PyQt4

    I am using macbook pro 13, bigsur 11.4, python3.7, I have installed code2pdf 1.0.0 version I got error no module named PyQt4 with command code2pdf -h, I got requirements with PyQt5, so why is this with PyQt4? (base) [chenzuoli@chenzuolis-MacBook /Users/chenzuoli/PycharmProjects]$code2pdf -h Traceback (most recent call last): File "/Users/chenzuoli/opt/anaconda3/bin/code2pdf", line 5, in <module> from Code2pdf.code2pdf import main File "/Users/chenzuoli/opt/anaconda3/lib/python3.7/site-packages/Code2pdf/code2pdf.py", line 2, in <module> from PyQt4.QtGui import QTextDocument, QPrinter, QApplication ModuleNotFoundError: No module named 'PyQt4'

    opened by chenzuoli 0
  • The output pdf file is not highlighted

    The output pdf file is not highlighted

    I'm using python3.7 and my os is windows 10. I built from the source code.

    I tried different styles but none of them were highlighted. image

    There were no errors or warnings in the cmd.

    I guess it doesn't work on the windows platform?

    opened by nekogee 1
  • [Feature Add] Put a title to the pdf

    [Feature Add] Put a title to the pdf

    A option to put a title to the pdf, like the fle name, will be great.

    I usually print multiple files(somtimes an entire project), and sometimes it gets mixed up.

    feature 
    opened by hjeonee 1
Owner
Tushar Gautam
Learning a bit of everything. Formerly: Google Summer of Code, 2016 @coala
Tushar Gautam
A simple Python script to convert multiple images (well technically also a single image) into a pdf.

PythonImage2PDF A simple Python script to convert multiple images into a single PDF-document. Created basically for only my own needs for converting m

Joona Gynther 1 Jun 28, 2022
PyPDF2 is a pure-python PDF library capable of splitting, merging together, cropping, and transforming the pages of PDF files.

PyPDF2 is a pure-python PDF library capable of splitting, merging together, cropping, and transforming the pages of PDF files. It can also add custom data, viewing options, and passwords to PDF files. It can retrieve text and metadata from PDFs as well as merge entire files together.

Matthew Stamy 5k Jan 4, 2023
PDFSanitizer - Renders possibly unsafe PDF files and outputs harmless PDF files

PDFSanitizer Renders possibly malicious PDF files and outputs harmless PDF files

null 9 Jan 30, 2022
Trata PDF para torná-lo compatível com PDF/X e com impressoras em escala de cinza.

tratapdf Trata PDF para torná-lo compatível com PDF/X e com impressoras em escala de cinza. dependências icc-profiles ghostscript visualizador de PDF

null 1 Nov 30, 2021
Compare-pdf - A Flask driven restful API for comparing two PDF files

COMPARE-PDF A Flask driven restful API for comparing two PDF files. Description

Karthikeyan JC 3 Mar 13, 2022
Convert Lecture Videos to PDF

Convert Lecture Videos to PDF Description Want to go through lecture videos faster without missing any information? Wish you can read the lecture vide

Emilio Kartono 20 Nov 25, 2022
Convert MD files to PDF automatically (with CSS) 📄🚀

MD2PDF Action Convert MD files to PDF automatically (with CSS)! Converts a pattern described set of markdown files and converts them to pdf whilst app

Will Fantom 1 Feb 9, 2022
Merge multiple PDF files into one.

PDF Merger Merge multiple PDF files into one. Usage % python pdf_merger.py -h usage: pdf_merger.py [-h] [-o OUTPUT] [-f [FILES ...]] optional argumen

Duo Apps 6 Oct 3, 2022
Small python-gtk application, which helps the user to merge or split pdf documents and rotate, crop and rearrange their pages using an interactive and intuitive graphical interface

Small python-gtk application, which helps the user to merge or split pdf documents and rotate, crop and rearrange their pages using an interactive and intuitive graphical interface

null 1.8k Dec 29, 2022
Simple HTML and PDF document generator for Python - with built-in support for popular data analysis and plotting libraries.

Esparto is a simple HTML and PDF document generator for Python. Its primary use is for generating shareable single page reports with content from popular analytics and data science libraries.

Dom 76 Dec 12, 2022
borb is a library for reading, creating and manipulating PDF files in python.

borb is a library for reading, creating and manipulating PDF files in python.

Joris Schellekens 2.9k Jan 1, 2023
This book will take you on an exploratory journey through the PDF format, and the borb Python library.

This book will take you on an exploratory journey through the PDF format, and the borb Python library.

Joris Schellekens 281 Jan 1, 2023
Converting Html files to pdf using python script, pdfkit module and wkhtmltopdf.

Html-to-pdf-pdfkit-wkhtml- This repository has code for converting local html files and online html resources into pdf. It is an python script which u

Hemachandran P 1 Nov 9, 2021
pikepdf is a Python library for reading and writing PDF files.

A Python library for reading and writing PDF, powered by qpdf

null 1.6k Jan 3, 2023
Simple pdf editor while preserving structure and format.

SIMPdf Simple pdf editor while preserving structure and format.

Shashwat Singh 242 Jan 4, 2023
JoplinPdf2Images - Converts a PDF to images in Joplin and adds it to the specified note as a printout

joplinPdf2Images Converts a PDF to images in Joplin and adds it to the specified

Morten Haahr Kristensen 2 Apr 20, 2022
Python PDF Parser (Not actively maintained). Check out pdfminer.six.

PDFMiner PDFMiner is a text extraction tool for PDF documents. Warning: As of 2020, PDFMiner is not actively maintained. The code still works, but thi

Yusuke Shinyama 4.9k Jan 4, 2023
A python library for extracting text from PDFs without losing the formatting of the PDF content.

Multilingual PDF to Text Install Package from Pypi Install it using pip. pip install multilingual-pdf2text The library uses Tesseract which can be ins

Shahrukh Khan 49 Nov 7, 2022
pystitcher stitches your PDF files together, generating nice customizable bookmarks for you using a declarative markdown file as input

pystitcher pystitcher stitches your PDF files together, generating nice customizable bookmarks for you using a declarative input in the form of a mark

Nemo 387 Dec 10, 2022