[R] Compress (gzip) a pdf device

Martin Renner martin.renner at stonebow.otago.ac.nz
Thu Oct 1 19:26:43 CEST 2009


try pdftk. Not quite on the fly but should do the trick. (I saw this  
on this list a little while ago)


pdfComp <- function (pdfname){
   if (0){
     x <- tempfile()
     system (paste ("mv", pdfname, x))
     system (paste ("pdftk", x, "output", pdfname, "compress"))
     unlink (x)
   }
}

pdf ("test.pdf")
plot (1:10)
dev.off()
pdfComp ("test.pdf")

On 30 Sep 2009, at 00:25 , Rainer M Krug wrote:

> 2009/9/30 Daniele Amberti <daniele.amberti at ors.it>
>
>> I have not found an easy way to compress a file on filesystem.
>> Especially I'd like to compress a pdf from pdf() function/device.  
>> Is it
>> possible to compress It on the flight?
>> I'd like to do something like:
>> pdf(gzipconnection())
>> dev.off()
>>
>>
> I guess this boils down to a question I asked some time ago concerning
> getting the filename of a pdf() device, as I wanted to create a  
> compressed
> pdf from the uncompressed pdf created by R (not "zipping" the pdf).
> It does not seem to be possible, at least I did not get any response  
> which I
> could use to implement my idea (create my dev.off(), which calls  
> dev.off()
> and afterwards compresses the pdf by using the file name).
>
> If you find a solution, please let me know.
>
> Cheers,
>
> Rainer
>
> If It is not possible, how can I create a gzip with the pdf?
>>
>> Thanks
>> Daniele A.
>>
>>
>>
>> ________________________________
>> ORS Srl
>>
>> Via Agostino Morando 1/3 12060 Roddi (Cn) - Italy
>> Tel. +39 0173 620211
>> Fax. +39 0173 620299 / +39 0173 433111
>> Web Site www.ors.it
>>
>>
>> ------------------------------------------------------------------------------------------------------------------------
>> Qualsiasi utilizzo non autorizzato del presente messaggio e dei suoi
>> allegati ? vietato e potrebbe costituire reato.
>> Se lei avesse ricevuto erroneamente questo messaggio, Le saremmo  
>> grati se
>> provvedesse alla distruzione dello stesso
>> e degli eventuali allegati.
>> Opinioni, conclusioni o altre informazioni riportate nella e-mail,  
>> che non
>> siano relative alle attivit? e/o
>> alla missione aziendale di O.R.S. Srl si intendono non attribuibili  
>> alla
>> societ? stessa, n? la impegnano in alcun modo.
>>
>>       [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at 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.
>>
>
>
>
> -- 
> Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation  
> Biology,
> UCT), Dipl. Phys. (Germany)
>
> Centre of Excellence for Invasion Biology
> Natural Sciences Building
> Office Suite 2039
> Stellenbosch University
> Main Campus, Merriman Avenue
> Stellenbosch
> South Africa
>
> Cell:           +27 - (0)83 9479 042
> Fax:            +27 - (0)86 516 2782
> Fax:            +49 - (0)721 151 334 888
> email:          Rainer at krugs.de
>
> Skype:          RMkrug
> Google:         R.M.Krug at gmail.com
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.




More information about the R-help mailing list