Skip to content

Instantly share code, notes, and snippets.

@nate-xyz
Created July 23, 2022 20:43
Show Gist options
  • Select an option

  • Save nate-xyz/a73d1e820a260c0f60d42673152c54c1 to your computer and use it in GitHub Desktop.

Select an option

Save nate-xyz/a73d1e820a260c0f60d42673152c54c1 to your computer and use it in GitHub Desktop.
bash script to create printabe pdf of your code, using enscript, ps2pdf, and pdftk
#!/bin/bash
i=0
mkdir ./tmp
for file in $(find . -name \*.$1)
do
if [ $(cat $file | wc -l) -gt 0 ]
then
enscript -1RG --line-numbers --margins=0:0:0:0 -p ./tmp/output-$i.ps $file
ps2pdf ./tmp/output-$i.ps ./tmp/output-$i.pdf
((i=i+1))
fi
done
filelist=""
n=$(find ./tmp -name \*.pdf | wc -l)
((n=n-1))
for ((i=0;i<=$n;i++));
do
filelist+="./tmp/output-${i}.pdf "
done
pdftk ${filelist} cat output $1-output.pdf
sudo rm -R ./tmp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment