Re: [R] PDF Compression

2009-07-30 Thread Stephen Tucker

There was a previous post about this also:
http://tolstoy.newcastle.edu.au/R/e2/help/07/05/17475.html

I was able to use bitmap(,type="pdfwrite") on Ubuntu Linux but had trouble 
getting it to work on Windows. 
For now, it's kind of kludgey but I have in my .Rprofle (or .Rprofile.site on 
Windows):

compressPDF <- function(x) {
  system(paste("pdftk",x,"output",sub("\\.pdf","c.pdf",x),
   "compress dont_ask"))
  unlink(x)
}

so after I plot something I would call compressPDF() on the same pdf file
pdf("plot.pdf"); plot(1:10); dev.off()
compressPDF("plot.pdf")

which renames it from 'plot.pdf' to 'plotc.pdf' to remind myself that I already 
compressed it...

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] PDF Compression

2009-07-30 Thread Frank E Harrell Jr

Eduardo Leoni wrote:

PDF created by R is in vector format. If you really want smaller files
you can try creating PNGs instead. With a high enough resolution (e.g.
dpi=600) there won't be much difference in the printed version of your
document.

-eduardo
  


Eduardo,

It is not a good idea in general to use a non-scalable graphics 
solution.  In general png can be larger than pdf but other disadvantages 
are more important.


When I have created curves in R that are composed of thousands of data 
points, the compression of pdf I've achieved with pdftk has been amazing.


Frank




On Thu, Jul 30, 2009 at 7:55 AM, Benno Pütz wrote:
  

Thanks for this advice - and to second Gabor's experience: I just
tried it on a couple of my files and achieved reductions on the order
of 90% (28.6MB to 4.4MB and 1.5GB to 170MB)!

This file contains lots of small plots but also many scattersmooth()-
images ...

So I think it does quite well in my case.

   Benno

Am 30.Jul.2009 um 12:21 schrieb Gabor Grothendieck:



I just tried it with a recent pdf that was generated from R on
Windows Vista
with "R version 2.9.1 Patched (2009-07-16 r48939)".  This particular
one
was laden with many graphs and was reduced to 25% of the original
size so my experience with that one was that it made a huge
difference.

On Thu, Jul 30, 2009 at 5:59 AM, David
Keegan wrote:
  

Gabor,

Thanks for the suggestion. I tried pdftk but it made very
little difference.

Regards,
David.
--
[David Keegan david.kee...@shenick.com 353 1 2710818]
Gabor Grothendieck writes:
 > After generating the pdf try this using the free pdftk utilty:
 >
 >pdftk infile.pdf output outfile.pdf compress
 >
 > On Thu, Jul 30, 2009 at 5:13 AM, David Keegan

wrote:
  

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

  



--
Frank E Harrell Jr   Professor and Chair   School of Medicine
Department of Biostatistics   Vanderbilt University

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] PDF Compression

2009-07-30 Thread Eduardo Leoni
PDF created by R is in vector format. If you really want smaller files
you can try creating PNGs instead. With a high enough resolution (e.g.
dpi=600) there won't be much difference in the printed version of your
document.

-eduardo



On Thu, Jul 30, 2009 at 7:55 AM, Benno Pütz wrote:
> Thanks for this advice - and to second Gabor's experience: I just
> tried it on a couple of my files and achieved reductions on the order
> of 90% (28.6MB to 4.4MB and 1.5GB to 170MB)!
>
> This file contains lots of small plots but also many scattersmooth()-
> images ...
>
> So I think it does quite well in my case.
>
>        Benno
>
> Am 30.Jul.2009 um 12:21 schrieb Gabor Grothendieck:
>
>> I just tried it with a recent pdf that was generated from R on
>> Windows Vista
>> with "R version 2.9.1 Patched (2009-07-16 r48939)".  This particular
>> one
>> was laden with many graphs and was reduced to 25% of the original
>> size so my experience with that one was that it made a huge
>> difference.
>>
>> On Thu, Jul 30, 2009 at 5:59 AM, David
>> Keegan wrote:
>>> Gabor,
>>>
>>> Thanks for the suggestion. I tried pdftk but it made very
>>> little difference.
>>>
>>> Regards,
>>> David.
>>> --
>>> [David Keegan david.kee...@shenick.com 353 1 2710818]
>>> Gabor Grothendieck writes:
>>>  > After generating the pdf try this using the free pdftk utilty:
>>>  >
>>>  >    pdftk infile.pdf output outfile.pdf compress
>>>  >
>>>  > On Thu, Jul 30, 2009 at 5:13 AM, David Keegan>> > wrote:
>>>
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] PDF Compression

2009-07-30 Thread Benno Pütz
Thanks for this advice - and to second Gabor's experience: I just  
tried it on a couple of my files and achieved reductions on the order  
of 90% (28.6MB to 4.4MB and 1.5GB to 170MB)!

This file contains lots of small plots but also many scattersmooth()- 
images ...

So I think it does quite well in my case.

Benno

Am 30.Jul.2009 um 12:21 schrieb Gabor Grothendieck:

> I just tried it with a recent pdf that was generated from R on  
> Windows Vista
> with "R version 2.9.1 Patched (2009-07-16 r48939)".  This particular  
> one
> was laden with many graphs and was reduced to 25% of the original
> size so my experience with that one was that it made a huge
> difference.
>
> On Thu, Jul 30, 2009 at 5:59 AM, David  
> Keegan wrote:
>> Gabor,
>>
>> Thanks for the suggestion. I tried pdftk but it made very
>> little difference.
>>
>> Regards,
>> David.
>> --
>> [David Keegan david.kee...@shenick.com 353 1 2710818]
>> Gabor Grothendieck writes:
>>  > After generating the pdf try this using the free pdftk utilty:
>>  >
>>  >pdftk infile.pdf output outfile.pdf compress
>>  >
>>  > On Thu, Jul 30, 2009 at 5:13 AM, David Keegan> > wrote:
>>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] PDF Compression

2009-07-30 Thread David Keegan
Gabor,

Interesting.

I have had success compressing the pdf generated by R with
pdftk. However when I incorporate that in a pdflatex document it
ends up decompressed in the final pdf.

Regards,
David.
-- 
[David Keegan david.kee...@shenick.com 353 1 2710818]
Gabor Grothendieck writes:
 > I just tried it with a recent pdf that was generated from R on Windows Vista
 > with "R version 2.9.1 Patched (2009-07-16 r48939)".  This particular one
 > was laden with many graphs and was reduced to 25% of the original
 > size so my experience with that one was that it made a huge
 > difference.
 > 
 > On Thu, Jul 30, 2009 at 5:59 AM, David Keegan 
 > wrote:

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] PDF Compression

2009-07-30 Thread Gabor Grothendieck
I just tried it with a recent pdf that was generated from R on Windows Vista
with "R version 2.9.1 Patched (2009-07-16 r48939)".  This particular one
was laden with many graphs and was reduced to 25% of the original
size so my experience with that one was that it made a huge
difference.

On Thu, Jul 30, 2009 at 5:59 AM, David Keegan wrote:
> Gabor,
>
> Thanks for the suggestion. I tried pdftk but it made very
> little difference.
>
> Regards,
> David.
> --
> [David Keegan david.kee...@shenick.com 353 1 2710818]
> Gabor Grothendieck writes:
>  > After generating the pdf try this using the free pdftk utilty:
>  >
>  >    pdftk infile.pdf output outfile.pdf compress
>  >
>  > On Thu, Jul 30, 2009 at 5:13 AM, David Keegan 
> wrote:
>

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] PDF Compression

2009-07-30 Thread David Keegan
Gabor,

Thanks for the suggestion. I tried pdftk but it made very
little difference.

Regards,
David.
-- 
[David Keegan david.kee...@shenick.com 353 1 2710818]
Gabor Grothendieck writes:
 > After generating the pdf try this using the free pdftk utilty:
 > 
 >pdftk infile.pdf output outfile.pdf compress
 > 
 > On Thu, Jul 30, 2009 at 5:13 AM, David Keegan 
 > wrote:

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] PDF Compression

2009-07-30 Thread Gabor Grothendieck
After generating the pdf try this using the free pdftk utilty:

   pdftk infile.pdf output outfile.pdf compress

On Thu, Jul 30, 2009 at 5:13 AM, David Keegan wrote:
>
> Hi,
>
> I am generating a large number of graphs with pdf() and
> incorporating them in pdf document using pdflatex.
>
> According to the pdf() help:
>
>   'pdf' writes uncompressed PDF.  It is primarily intended for
>   producing PDF graphics for inclusion in other documents, and
>   PDF-includers such as 'pdftex' are usually able to handle
>   .compression.
>
> But pdflatex incorporates the R graphs without compressing them.
> They appear in the final document in cleartext, almost but not identical
> to what was generated by R.
>
> I tried the latex settings "\\pdfcompresslevel=9",
> "\\pdfobjcompresslevel=3". They reduced the overall size of
> the final document slightly, but didn't cause the embedded R
> graphs to be compressed.
>
> Can anyone suggest how I can get pdflatex to compress the R
> graphs while embedding them? My output files are very big,
> and I know they would be substantially smaller if the R
> graphs were compressed.
>
> Regards,
> David
> --
> [David Keegan david.kee...@shenick.com 353 1 2710818]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] PDF Compression

2009-07-30 Thread Paul Hiemstra

Hi,

You could have a look at exporting the pdfs using the Cairo package.

cheers,
Paul

David Keegan schreef:

Hi,

I am generating a large number of graphs with pdf() and
incorporating them in pdf document using pdflatex.

According to the pdf() help:

   'pdf' writes uncompressed PDF.  It is primarily intended for
   producing PDF graphics for inclusion in other documents, and
   PDF-includers such as 'pdftex' are usually able to handle
   .compression.

But pdflatex incorporates the R graphs without compressing them.
They appear in the final document in cleartext, almost but not identical
to what was generated by R.

I tried the latex settings "\\pdfcompresslevel=9",
"\\pdfobjcompresslevel=3". They reduced the overall size of
the final document slightly, but didn't cause the embedded R
graphs to be compressed.

Can anyone suggest how I can get pdflatex to compress the R
graphs while embedding them? My output files are very big,
and I know they would be substantially smaller if the R
graphs were compressed.

Regards,
David



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.