[texhax] Achieving the optimum quality of rendering
William F Hammond
hmwlfsr at yahoo.com
Tue Mar 4 05:20:49 CET 2014
William Adams <will.adams at frycomm.com> writes:
> Using Adobe Acrobat to Distill from .ps to .pdf will afford more
> options and control and be more in-line w/ what commercial printers
> want / expect, but there's no reason not to just make good quality
> .pdf files for inclusion into your pages, and then to use pdflatex and
> go straight to .pdf.
For pdf output I think it's a bit more complicated than that.
It depends on what is the original format for the image. You
want both the image used for pdf output and the image used for
dvi output to be as close as possible to the original image.
For example, if the original is eps, then "epstopdf" (found on
CTAN or in many TeX distributions) will make good pdf for use
with \includegraphics toward pdf output.
But if the original image is png or jpeg, then
\includegraphics will use that with pdflatex (so long as no
pdf file with the same stem name is present). In this case
the challenge will be to generate an eps version, albeit
really not good vector graphics, for use with
\includegraphics toward dvi output. For this one wants to
employ the excellent code contributed by Hans Hagen for
including bitmap graphics in pdf output made with pdflatex.
Toward this end I use a script something like this (in
Bourne dialect):
---
#!/bin/sh
#
# png2eps
#
# REQUIRED:
# pdflatex
# ghostscript (for pdf2ps)
# ImageMagick (for identify)
#
# This generates ${stem}.pdf and ${stem}.eps from ${stem}.png
# Useful, for example, in the case where the original graphic is a screenshot
# The primary engine is pdflatex with 'geometry' for making a clean .pdf
# Ghostscript's pdf2ps is used to make a .ps that is then cleaned with ps2eps
#
# WARNING: If "${stem}.pdf" exists, it will be moved to "${stem}.pdf~".
# Ditto for "${stem}.eps".
#
# multiplier for converting pixels to basis points (one might want to adjust)
px2bp="0.752"
#
pname="`basename ${0}`"
usage1="Usage: ${pname} stemname"
usage2=" to make {stemname}.eps from {stemname}.(png|jpg)"
#
debugflag=0
nosaveflag=1
stem=""
case $# in
0)
echo "$usage1"
echo "$usage2"
exit 1
;;
2)
case $1 in
-d)
debugflag=1
stem="${2}"
;;
-s)
nosaveflag=0
stem="${2}"
;;
-ds)
debugflag=1
nosaveflag=0
stem="${2}"
;;
-sd)
debugflag=1
nosaveflag=0
stem="${2}"
;;
*)
echo "$usage1"
exit 2
;;
esac
;;
1)
stem="${1}"
;;
*)
echo "$usage1"
exit 2
;;
esac
iname=""
if [ -r "${stem}.png" ] ; then
iname="${stem}.png"
elif [ -r "${stem}.jpg" ] ; then
iname="${stem}.jpg"
else
echo "${pname}: Cannot read ${stem}.png or ${stem}.jpg"
exit 3
fi
texname="${pname}$$.tex"
logname="${pname}$$.log"
auxname="${pname}$$.aux"
pdftname="${pname}$$.pdf"
pdfname="${stem}.pdf"
psname="${pname}$$.ps"
epstname="${pname}$$.eps"
epsname="${stem}.eps"
if [ -f "$pdfname" ] ; then
rm -f "${pdfname}~"
mv "${pdfname}" "${pdfname}~"
fi
if [ -f "$epsname" ] ; then
rm -f "${epsname}~"
mv "${epsname}" "${epsname}~"
fi
dims=`identify "${iname}" | awk '{print $3}'`
hdim=`echo "${dims}" | \
awk -Fx -v "c=${px2bp}" '{h=$1;a=1.01*h*c;printf("%sbp",a);}'`
vdim=`echo "${dims}" | \
awk -Fx -v "c=${px2bp}" '{h=$2;a=1.01*h*c;printf("%sbp",a);}'`
hdims=`echo "${dims}" | \
awk -Fx -v "c=${px2bp}" '{h=$1;a=h*c;printf("%sbp",a);}'`
if [ $debugflag -eq 1 ] ; then
echo "hdim is $hdim"
echo "vdim is $vdim"
echo "iname is $iname"
echo "texname is $texname"
echo "pdftname is $pdftname"
echo "pdfname is $pdfname"
echo "psname is $psname"
echo "epstname is $epstname"
echo "epsname is $epsname"
echo "debugflag is $debugflag"
echo "nosaveflag is $nosaveflag"
fi
cat > "$texname" - << PNG2EPS_EOF
\documentclass{article}
\usepackage[margin=0bp,nohead,paperwidth=${hdim},paperheight=${vdim}]{geometry}
\usepackage{graphicx}
\begin{document}
\begin{center}
\includegraphics[width=${hdims}]{${stem}}
\end{center}
\end{document}
PNG2EPS_EOF
pdflatex "$texname"
if [ "$?" = "0" ] ; then
rm "$logname"
rm "$auxname"
mv "$pdftname" "$pdfname"
if [ "$nosaveflag" = 1 ] ; then
rm "$texname"
fi
else
echo "${pname}: pdflatex failed"
exit 4
fi
pdf2ps "$pdfname" "$psname"
if [ "$?" = "0" ] ; then
if [ "$nosaveflag" = 1 ] ; then
rm "$pdfname"
fi
else
echo "${pname}: pdf2ps failed"
exit 5
fi
# Note: ps2eps does not allow an output name spec
# Presumably the output for "${pname}$$.ps"
# will be "${pname}$$.eps"
ps2eps "$psname"
if [ "$?" = "0" ] ; then
if [ "$nosaveflag" = 1 ] ; then
rm "$psname"
mv "$epstname" "$epsname"
fi
else
echo "${pname}: ps2eps failed"
exit 6
fi
---
-- Bill
Email: hmwlfsr at yahoo.com
gellmu at gmail.com
https://www.facebook.com/william.f.hammond
http://www.albany.edu/~hammond/
More information about the texhax
mailing list