## jpeg compression in pdf files

David Larson
Posts: 11
Joined: September 25 2004
Affiliation: Johns Hopkins University

### jpeg compression in pdf files

For the few presentations I've made so far, I have created a .pdf file for my talk (using the seminar document class in latex) and presented it with acrobat reader. This seems to work fairly well.

However, when creating a pdf file with the linux utilities "dvipdf" or "pstopdf", some of my figures get compressed much further, which degrades their resolution. If I look closely, I see the same artifacts that one sees in an overly compressed jpeg image. This applies to images (such as maps of the CMB) which have been converted from .png or .jpg files to encapsulated postscript and included in the document. My postscript file for the presentation looks fine; it's just the pdf file that has too much compression.

Has anyone else run into this problem and solved it?

Ben Gold
Posts: 81
Joined: September 25 2004
Affiliation: University of Minnesota
Contact:
You can probably avoid most problems by using "pdftex" or "pdflatex" to simply make the .pdf files straight from the TeX source. I'd highly recommend using these. You might already have them installed and not even know it.

If you really can't go that route, try using "dvips -Ppdf" when you turn your dvi files into postscript. This tells dvips that you're ultimately intending to convert to pdf format and fixes some issues that can occur when using "pstopdf" on the file, although I don't know if it will address your particular problem.

Also, if you're really stuck, I think "pdf2ps -dPDFSETTINGS=/printer" or "pdf2ps -dPDFSETTINGS=/prepress" might help.

David Larson
Posts: 11
Joined: September 25 2004
Affiliation: Johns Hopkins University
Thank you. While pdftex doesn't work (I wrote in latex) and pdflatex gives me the wrong page size and doesn't include the images, the "ps2pdf -dPDFSETTINGS=/prepress" and "ps2pdf -dPDFSETTINGS=/printer" do improve the quality of the jpeg images. They are probably the simplest solution to the problem.

I did a little more research. To do a lossless compression of the images, I used
ps2pdf -dAutoFilterColorImages=false -dColorImageFilter=/FlateEncode

To be able to finely control the compression of the images, I had to come up with an incantation similar to the following, which should all be on one line (to convert ABC.ps to ABC.pdf):
cat ABC.ps | gs -sDEVICE=pdfwrite -sOutputFile=ABC.pdf -dAutoFilterColorImages=false -c "<< /ColorImageDict << /QFactor 0.1 /Blend 1 /HSample [1 1 1 1] /VSample [1 1 1 1] >> >> setdistillerparams" -

Adjusting the QFactor away from 0.1 adjusts the quality of compression, but I don't know what range of values it can take (although 0.9 is default).

For some partially helpful information, see
http://casper.ghostscript.com/~ghostgum/pdftips.htm
and
http://www.cs.wisc.edu/~ghost/doc/cvs/Ps2pdf.htm

Having spent too much time on this, I will now go back to doing research.

Ben Gold
Posts: 81
Joined: September 25 2004
Affiliation: University of Minnesota
Contact:
Glad you got it working. For future reference, I should have mentioned that when you use pdftex or pdflatex with figures, you'll also want something like the following near the beginning of your TeX file:

Code: Select allp>

\usepackage&#123;graphicx&#125;
\DeclareGraphicsExtensions&#123;.pdf, .jpg, .png&#125;
After this point \includegraphics should work as you'd expect. To fix the page size issues it's probably best to take care of it once and for all by modifying your "pdftex.cfg" file. Mine happens to be in

Code: Select allp>

/usr/local/teTeX/share/texmf.local/pdftex/config/
but this can change depending on your installation. Once you've found it, you can change a few lines to look like

Code: Select allp>

page_width 8.5 true in
page_height 11 true in
There are also other options like "compress_level" that you can play with, see http://miktex.org/manual/pdftexcfg.html for a description of them. So this involves a little setup, but in the long run it's hopefully easier than dealing with obscure gs options.