Skip to content

Instantly share code, notes, and snippets.

@wizofe
Forked from smoitra87/python2pdf.sh
Created August 15, 2019 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wizofe/0f6df2c3a3a2746c77c2e768aedee873 to your computer and use it in GitHub Desktop.
Save wizofe/0f6df2c3a3a2746c77c2e768aedee873 to your computer and use it in GitHub Desktop.
Convert python files to pdf and concatenate all pdfs. Requires pygmentize, pdflatex and pdftk
#!/bin/sh
allpdfs=""
for f in "$@" ; do
filename=$(basename "$f")
filename="${filename%.*}"
pygmentize -f tex -O linenos -O title=$( echo $filename | tr '_' '-').py -O full -O style=default -o /tmp/$filename.tex $f
pdflatex -jobname=$filename -output-directory=/tmp /tmp/$filename.tex
allpdfs="$allpdfs /tmp/$filename.pdf"
done
pdftk $allpdfs cat output /tmp/combined.pdf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment