0

Hello fellow R enthusiasts,

I am wondering whether we can create a pdf version from docx within R (not using other conversion tools). I create a docx report using ReporteRs package. I would like to make a copy of that in pdf copy. Is it possible within R, without using any external softwares? Thank you in advance.

Marat Talipov
  • 13,064
  • 5
  • 34
  • 53
JeanVuda
  • 1,738
  • 14
  • 29
  • 1
    `pdf('your_file_name.pdf')` `#do stuff here that prints graphs` `dev.off()` – Michal Jun 10 '15 at 20:10
  • 1
    Why don't you just change your code by a bit and use R-Sweave instead. No need to go from Markdown -> docx -> PDF. – Vlo Jun 10 '15 at 20:15
  • I am aware of pdf function to print graphs. But I am not sure whether it can print the list used in `Reporters` package and convert it to a multipage pdf document. Thank you for your suggestion though. – JeanVuda Jun 10 '15 at 20:16
  • 4
    Apparently ReporteRs could generate markdown `mydoc = addMarkdown( mydoc, text = mkd, default.par.properties = parProperties(text.align = "justify", padding.left = 0) )`, so you could save a Rmd file `write(mydoc, file = "input.Rmd", )`, then use rmarkdown to print a pdf `render("input.Rmd", "pdf_document")` – Robert Jun 10 '15 at 21:08
  • @Robert where does the `write function` comes from? Base? I don't see a `write` function in `ReporteRs`. Thank you for your suggestion though. – JeanVuda Jun 11 '15 at 04:03
  • Yes, it is from Base. Tell us if it works! – Robert Jun 12 '15 at 01:38
  • @Robert, no it didn't work. It threw an error.I am not sure whether a list made by `Reporters` can be converted to Rmd easily like that. – JeanVuda Jun 12 '15 at 06:45

1 Answers1

2

Here is one way to do it. Disclaimer: This answer came up in google group of ReporteRs.

writeDoc( doc, file = docfile)
system(paste("libreoffice --headless --convert-to pdf  ", docfile), intern = TRUE)

It needs libreoffice application to be installed in your system.

JeanVuda
  • 1,738
  • 14
  • 29