[R] PDF Compression

Stephen Tucker brown_emu at yahoo.com
Thu Jul 30 17:25:42 CEST 2009


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...




More information about the R-help mailing list