-
-
Save wizofe/c89bfbfaae3f3fb2a5df164cd7786d8a to your computer and use it in GitHub Desktop.
Convert python files to pdf and concatenate all pdfs. Requires pygmentize, pdflatex and pdftk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Run as ./python2pdf.sh $(ls *.py) | |
# For Debian the requirements are | |
# sudo apt install pdftk python3-pygments texlive-latex-base texlive-fonts-recommended texlive-fonts-extra texlive-latex-extra | |
outdir=${HOME}/tmp | |
mkdir ${outdir} | |
allpdfs="" | |
for f in "$@" ; do | |
filename=$(basename "$f") | |
filename="${filename%.*}" | |
pygmentize -f tex -O title=$( echo $filename | tr '_' '-').py -O full -O style=default -o ${outdir}/$filename.tex $f | |
pdflatex -jobname=$filename -output-directory=${outdir} ${outdir}/$filename.tex | |
allpdfs="$allpdfs ${outdir}/$filename.pdf" | |
done | |
pdftk $allpdfs cat output ${outdir}/combined.pdf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment