R/distill.R

Defines functions distill

Documented in distill

#' Use ghostscript to distill a PDF, possibly to grayscale.
#'
#' @param file A file name
#' @param gray Whether the output should be grayscale
#'
#' @return NULL
#' @export
distill <- function(file,
                    gray = F) {
  if (!gray) {
    system(paste0("gs -sDEVICE=pdfwrite -dNOPAUSE -dQUIET -dBATCH -dCompatibilityLevel=1.4 -sColorConversionStrategy=/CMYK -dPDFSETTINGS=/prepress -dEmbedAllFonts=true -dSubsetFonts=false -dAutoRotatePages=/None -sOutputFile=./temp.pdf ", file))
  } else {
    system(paste0("gs -sDEVICE=pdfwrite -dNOPAUSE -dQUIET -dBATCH -dCompatibilityLevel=1.4 -sColorConversionStrategy=/Gray -dPDFSETTINGS=/prepress -dEmbedAllFonts=true -dSubsetFonts=false -dAutoRotatePages=/None -sOutputFile=./temp.pdf ", file))
  }
  system(paste0("rm ", file))
  system(paste0("mv ./temp.pdf ", file))
  if (!gray) {
    system(paste0("convert -density 600 ", file, " ", gsub(".pdf", ".png", file)))
  } else {
    system(paste0("convert -colorspace gray -density 600 ", file, " ", gsub(".pdf", ".png", file)))
  }
}
bocinsky/guedesbocinsky2018 documentation built on May 3, 2019, 8:59 p.m.