Skip to content

Instantly share code, notes, and snippets.

@vmrob
Created May 13, 2015 03:45
Show Gist options
  • Save vmrob/ac9f44d18b5a5944bcaa to your computer and use it in GitHub Desktop.
Save vmrob/ac9f44d18b5a5944bcaa to your computer and use it in GitHub Desktop.
Script to convert a pdf to png
#!/bin/bash -e
Root=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
if [[ $1 == "" ]] ; then
echo "usage: generate-gitdag.sh input.tex [density (default 300)]"
exit;
fi
Density=300
if [[ $2 != "" ]] ; then
echo "Using density of $2"
Density=$2
fi
function cleanup() {
rm -rf $TempFolder
}
trap cleanup SIGTERM SIGINT
# TempFolder="Temp-$RANDOM"
TempFolder="Temp"
mkdir -p $TempFolder
BaseFileName=$TempFolder/$(basename $1 .tex)
Final=$(basename $1 .tex).png
# Other method, still a bug in imagemagick. Increase density greatly and
# resize to reduce artifacts
# max_print_line=200 latex -interaction batchmode -output-directory $TempFolder $1
# dvisvgm $BaseFileName.dvi --color --output=$BaseFileName.svg
max_print_line=200 pdflatex -interaction batchmode -output-directory $TempFolder $1
convert -density $Density -strip $BaseFileName.pdf $Final
cleanup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment