R/pdf_expand.R

Defines functions pdf_expand

Documented in pdf_expand

#' Expand PDF page size
#'
#' Expand the page size of a PDF file to include all of its contents. Requires \code{inkscape} command-line utility.
#'
#' The function modifies an existing PDF file!
#'
#' @param filename A PDF file name or file path
#'
#' @return NULL
#'
#' @export
#'
#' @examples
#' \dontrun{
#' pdf_expand(filename = "~/test.pdf")
#' }

pdf_expand = function(filename) {
  input = normalizePath(filename)
  tmp_svg = gsub("\\.pdf$", "\\.svg", input)
  system(paste0('inkscape -z -f ', filename, ' -l ', tmp_svg))
  system(paste0("inkscape --verb=FitCanvasToDrawing --verb=FileSave --verb=FileQuit ", tmp_svg))
  system(paste0("inkscape ", tmp_svg, " --export-pdf=", input))
  system(paste0("rm ", tmp_svg))
}
michaeldorman/geobgu documentation built on Jan. 6, 2021, 3:57 p.m.