rofficer

Saving pptx as pdf in R


I have created powerpoint files using officer package and I would also like to save them as pdf from R (dont want to manualy open and save as pdf each file). Is this possible?


Solution

  • you can save the powerpoint object edited using the code which is posted here: create pdf in addition to word docx using officer.

    You will need to first install pdftools and libreoffice

    library(pdftools)
    office_shot <- function( file, wd = getwd() ){
      cmd_ <- sprintf(
        "/Applications/LibreOffice.app/Contents/MacOS/soffice --headless --convert-to pdf --outdir %s %s",
        wd, file )
      system(cmd_)
    
      pdf_file <- gsub("\\.(docx|pptx)$", ".pdf", basename(file))
      pdf_file
    }
    office_shot(file = "your_presentation.pptx")
    

    Note that the author of the officer package is the one who referred someone to this response.