Skip to content

Instantly share code, notes, and snippets.

@biji
Created September 30, 2020 11:49
Show Gist options
  • Save biji/9289d4f5e5b7ac169eda3664c39a4dbd to your computer and use it in GitHub Desktop.
Save biji/9289d4f5e5b7ac169eda3664c39a4dbd to your computer and use it in GitHub Desktop.
Convert many svgz in folders to pdf
for DIR in */; do
if [ -f "$DIR" ]
then
continue
fi
BASENAME=`basename "$DIR"`
echo "$DIR"
mkdir -p "$DIR/pdf"
MAX=0
for a in `seq 1 500`; do
FILE="p$a.svgz"
FILE2="p$a.svg"
FILE3="p$a.pdf"
if [ -f "$DIR/$FILE" ]
then
echo "$FILE"
ln "$DIR/$FILE" "$DIR/$FILE2"
if [ -f "$DIR/pdf/$FILE3" ]
then
echo "skip $FILE3"
else
google-chrome --headless --disable-gpu --print-to-pdf-no-header --print-to-pdf="$DIR/pdf/$FILE3" "$DIR/$FILE2"
fi
else
break
fi
MAX=$a
done
pushd .
cd "$DIR/pdf"
pdfunite $(eval echo p{1..$MAX}.pdf) "$BASENAME.pdf"
popd
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment