Skip to content

eljuanchosf/source-code-to-pdf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 

Repository files navigation

source-code-to-pdf

Origins

This useful utility was born out of the necessity of putting the source code of a friend's app into a PDF. I couldn't find anything ready to use, but @terdon created a fantastic script that uses LaTeX, I took it and crafted this horrible, but useful, big BASH script. :)

How to use

WARNING: tested ONLY in Ubuntu 14.04

cd to-your-awesome-project-root
wget https://raw.githubusercontent.com/eljuanchosf/source-code-to-pdf/master/src2pdf
chmod +x src2pdf
vim src2pdf
# Edit the variables in the top of the file
./src2pdf my_source_code

The output file will be my_source_code.pdf, but also the LaTeX file will be left in case you want to use it.

File types

There is one very important code block. It is used to specify which files we want to include and what languages are they written:

# The language    # File pattern # Exclude files
file_types[0]="php|-name '*.php'|! -name '*.blade.php'"
file_types[1]="html|-name '*.blade.php'|"

In the example, I go for php and .blade.php files. Since Python's Pygments doesn't have a blade format, I set it as HTML. In this way, Pygments will know what language to use when doing the syntax highlightning.

You can add as many groups as you want. Copy, paste and replace.

Each group's section is sepparated by a pipe (|):

  • The first section is the language name according to Pygments specification.
  • The second section is a pattern on what files do you want to include.
  • The third section is a pattern on what files do you want to exclude.

There is nothing more to it... enjoy! (let me know if you use it!)

Want to contribute?

Fork, modify, commit, push, pull request. :)

About

A BASH script to put your source code to PDF

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages