Created
April 7, 2016 10:10
-
-
Save huwan/11ab4ca3d6e83adcc4cd520e2627b49c to your computer and use it in GitHub Desktop.
pdf2eps: A shell script for easy and efficient conversion pdf figures to eps
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/bash | |
# Alireza Haghdoost pdf2eps converter | |
# http://ce.sharif.edu/~haghdoost/mypages/pdf2eps.html | |
# http://tex.stackexchange.com/questions/20883/how-to-convert-pdf-to-eps | |
# | |
# Need xpdf(pdftops) and texlive-extra-utils(pdfcrop) package to work on Linux OS | |
# | |
# Usage: $ pdf2eps foo.pdf | |
# or $ pdf2eps *.pdf | |
function timer() | |
{ | |
if [[ $# -eq 0 ]]; then | |
echo $(date '+%s') | |
else | |
local stime=$1 | |
etime=$(date '+%s') | |
if [[ -z "$stime" ]]; then stime=$etime; fi | |
dt=$((etime - stime)) | |
ds=$((dt % 60)) | |
dm=$(((dt / 60) % 60)) | |
dh=$((dt / 3600)) | |
printf '%d:%02d:%02d' $dh $dm $ds | |
fi | |
} | |
for i in $@ | |
do | |
t=$(timer) | |
echo -e "$i" | sed 's/\(.*\)\..*/\1/' >temp.out | |
read NAME <temp.out | |
echo -e "$i"|awk -F . '{print $NF}' >temp.out | |
read EXT <temp.out | |
if [ "$EXT" = 'pdf' -o "$EXT" = 'PDF' ] | |
then | |
echo "Converting $i to eps format" | |
pdfcrop "$i" "$NAME-tmp.pdf" | |
pdftops -eps "$NAME-tmp.pdf" "$NAME.eps" | |
if [ $? -eq 0 ] | |
then | |
echo -e "$NAME.pdf converted to $NAME.eps" | |
printf 'Elapsed time: %s\n' $(timer $t) | |
fi | |
rm "$NAME-tmp.pdf" | |
echo "----------------------" | |
else | |
echo " $i is not a pdf file " | |
echo "----------------------" | |
fi | |
done | |
rm temp.out |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment