[OS X TeX] Compressing pdf graphics

Chabot Denis chabotd at globetrotter.net
Thu May 24 06:23:47 CEST 2007


Hi again,

Here is a summary of what I have learned about the options to  
compress/convert individual pdf graphics before I include them in a  
LaTeX document.

I started by producing a rather large graphic file with R. I saved it  
as a pdf and as a postscript file:

-rw-r--r--   1 chabotd  chabotd   3384788 May 23 20:54  
fig_pdf_from_R.pdf
-rw-r--r--   1 chabotd  chabotd   1426330 May 23 20:54 fig_ps_from_R.ps

Then I did the following, with file sizes shown in the same order below:

- convert the ps file to pdf using Preview, epstopdf, or ps2pdf, or  
pstopdf. All but the last one gave similar sizes.

-rw-r--r--   1 chabotd  wheel     3749887 May 24 00:14  
fig_ps_Preview.pdf
-rw-r--r--   1 chabotd  chabotd   3354762 May 23 23:55  
fig_ps_epstopdf.pdf
-rw-r--r--   1 chabotd  chabotd   3356223 May 23 21:12 fig_ps_ps2pdf.pdf
-rw-r--r--   1 chabotd  chabotd  11397461 May 23 23:51  
fig_ps_pstopdf.pdf

- I also tried to shring the pdf file produced by R. In order: print- 
to-compress-pdf from Skim (or any other app) and pdftk. The latter  
was the winner overall. Text remained searchable in all methods.

-rw-r--r--   1 chabotd  chabotd    379307 May 23 22:31  
fig_pdf_comptk.pdf
-rw-r--r--   1 chabotd  chabotd    520506 May 23 21:16  
fig_pdf_print_to_comppdf.pdf



Denis


> Subject: Re: [OS X TeX] Compressing pdf graphics
> From: "David Watson" <dewatson at mac.com>
> Date: Tue, 22 May 2007 19:31:16 -0500
>
> I don't have any idea how to compress within (La)TeX, but you might
> want to use the postscript output capability of R combined with the
> command-line utilities ps2pdf, ps2pdf12, ps2pdf13, or ps2pdf14
> provided with Ghostscript. Depending on your version of ghostscript,
> you can find some documentation on these at
>
>       file:///usr/local/share/ghostscript/8.54/doc/Ps2pdf.htm
>
> (you may need to change the 8.54 to whatever version you have  
> installed)
>
> I did a quick test on a simple plot and found some size advantages
> over the pdf() function in R.
>
> On May 22, 2007, at 12:14 PM, Chabot Denis wrote:
>
>> Hi,
>>
>> Recently I posted a question to the R mailing list because pdf
>> plots I make with it can be larger than png files when a lot of
>> objects are plotted (but offer much better quality, of course, in
>> particular for zooming in on details).
>>
>> What prompted my question was the fact that Acrobat can shrink
>> these graphics (or my LaTeX documents that contain lots of them)
>> quite a bit, and I was hoping there was a compression option I did
>> not know about.
>>
>> I'm including a reply I received because it suggests this
>> compression can be done within LaTeX.
>>
>> Do you know how to do this?
>
>
> ----------------------------------------------------------------------
>
> Subject: Re: [OS X TeX] Compressing pdf graphics
> From: "David Watson" <dewatson at mac.com>
> Date: Tue, 22 May 2007 19:36:11 -0500
>
> Sorry, I forgot to mention that you can get a better bounding box on
> your eps file by using epstopdf (an Apple utility). The size is about
> the same as the ps2pdf route.
>
> ----------------------------------------------------------------------
>
> Subject: Re: [OS X TeX] Compressing pdf graphics
> From: "David Watson" <dewatson at mac.com>
> Date: Tue, 22 May 2007 19:55:49 -0500
>
> I just discovered that you can achieve approximately identical
> results as epstopdf (Apple) using gs with
>
>      ps2pdf -dEPSCrop myfile.eps
>
> In R, use something like
>
>      postscript("myfile.eps", width=4.0, height = 3.0,
> horizontal=FALSE, onefile=FALSE, paper="special")
>
> to get the "eps" file.
>
> Perhaps someone else can assist you on the problem of including fonts
> families other than the standard Postscript fonts into your eps files.
>
>
>
>
> ----------------------------------------------------------------------
> Subject: Re: [OS X TeX] Compressing pdf graphics
> From: "Guido Mocken" <mocken at mpi-hd.mpg.de>
> Date: Wed, 23 May 2007 09:50:42 +0200
>
> Am 22.05.2007 um 22:40 schrieb Maarten Sneep:
>
>> pdftk [1] will compress pdf files for you, either the individual
>> graphics, or the final (pdflatex) output.
>
> This is definitely the way to go, because it is *lossless*
> compression. To be more precise:
>
> pdftk input.pdf output output.pdf compress
>
> I can compress my pdflatex-generated PHD thesis (which contains a lot
> of pictures) from 70 MB to just 7 MB this way without any loss of
> quality.
> Of course, I can achieve the same ratio using gzip or bzip2, but then
> the file can no longer be opened directly in a PDF reader.
>
> Guido
>
>
> ----------------------------------------------------------------------
> Subject: Re: [OS X TeX] Compressing pdf graphics
> From: "Victor Ivrii" <vivrii at gmail.com>
> Date: Wed, 23 May 2007 05:20:43 -0700
>
> On 5/23/07, Guido Mocken <mocken at mpi-hd.mpg.de> wrote:
>> Am 22.05.2007 um 22:40 schrieb Maarten Sneep:
>>
>>> pdftk [1] will compress pdf files for you, either the individual
>>> graphics, or the final (pdflatex) output.
>>
>> This is definitely the way to go, because it is *lossless*
>> compression. To be more precise:
>>
>> pdftk input.pdf output output.pdf compress
>>
>> I can compress my pdflatex-generated PHD thesis (which contains a lot
>> of pictures) from 70 MB to just 7 MB this way without any loss of
>> quality.
>> Of course, I can achieve the same ratio using gzip or bzip2, but then
>> the file can no longer be opened directly in a PDF reader.
>>
>> Guido
>>
>
>
> Note that one way to reduce size is using Acrobat and to require
> compatibility only with higher versions. However then it may become
> incompatible with the earlier versions of Acrobat; pretex compression
> can make it incompatible with TeX (the latest pdftex 1.40 accepts pdf
> <= 1.5 which corresponds to  Acrobat 6)
>
>
> --
> ========================
> Victor Ivrii, Professor, Department of Mathematics, University of  
> Toronto
> http://www.math.toronto.edu/ivrii
>
> ----------------------------------------------------------------------
>
> Subject: Re: [OS X TeX] Compressing pdf graphics
> From: "Maarten Sneep" <maarten.sneep at xs4all.nl>
> Date: Wed, 23 May 2007 19:48:03 +0200
>
> On May 23, 2007, at 02:55, David Watson wrote:
>
>> I just discovered that you can achieve approximately identical
>> results as epstopdf (Apple) using gs with
>
> epstopdf is a perl script that uses ghostscript (which is used by
> ps2pdf as well).
> pstopdf is the Apple command line tool that converts postscript to
> pdf (the same tool used by preview, and actually the Adobe distiller
> with sane but fixed parameters).
>
> Maarten
>
>
> ----------------------------------------------------------------------
>
> Subject: Re: [OS X TeX] Compressing pdf graphics
> From: "Nestor Aguilera" <aguilera at ceride.gov.ar>
> Date: Wed, 23 May 2007 18:45:07 -0300
>
>
> On 23 May, 2007, at 14:48, Maarten Sneep wrote:
>
>> epstopdf is a perl script that uses ghostscript (which is used by
>> ps2pdf as well).
>> pstopdf is the Apple command line tool that converts postscript to
>> pdf (the same tool used by preview, and actually the Adobe
>> distiller with sane but fixed parameters).
>
> In my MacBook, Preview, eps2pdf and epstopdf produce quite different
> results. Applied to a particular .ps file, and then looking for File -
>> Properties in Acrobat Reader, I see
>
>     with        producer                            PDF
> version          size
>     Preview     Mac OSX 10.4.9 Quartz PDFContext    1.3 (Acrobat
> 4.x)    364 KB
>     ps2pdf      GPL Ghostscript 8.54                1.3 (Acrobat
> 4.x)    168 KB
>     pstopdf     Apple pstopdf                       1.3 (Acrobat
> 4.x)    264 KB
>
> It seems that the the output of pstopdf is the cleanest: I can search
> for strings (and find them), but not for the other two.
>
> Best,
>
>                                                   Nestor
>
> ----------------------------------------------------------------------


------------------------- Helpful Info -------------------------
Mac-TeX Website: http://www.esm.psu.edu/mac-tex/
TeX FAQ: http://www.tex.ac.uk/faq
List Archive: http://tug.org/pipermail/macostex-archives/
List Reminders & Etiquette: http://www.esm.psu.edu/mac-tex/list/





More information about the macostex-archives mailing list