0
votes

Have r Shiny app and Rmd file. Trying to download with downloadHandler() but getting an Adobe Acrobat error saying:

"Acrobat could not open 'rstudio-iV1460.pdf' because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded)."

Found that this is due to using Acrobat v11.0 and needing to ensure head of document is formatted with %PDF string.

reference: https://helpx.adobe.com/acrobat/kb/pdf-error-1015-11001-update.html

Question: Where do I put this %PDF and how do I resolve this issue? Do I put it in the Rmd document or in the tex document?

Here is how I'm producing the pdf from the Rmd in my r Shiny app:

server.r

shinyServer(function(input, output) {

# dowload from Rmd file
output$downloadReport <- downloadHandler(
  filename = 'input.pdf',

  content = function(file) {
    src <- normalizePath('input.Rmd')

    # temporarily switch to the temp dir, in case you do not have write
    # permission to the current working directory
    owd <- setwd(tempdir())
    on.exit(setwd(owd))
    file.copy(src, 'input.Rmd')

    library(rmarkdown)
    out <- render('input.Rmd', pdf_document())
    file.rename(out, file)
  }
)
}

input.Rmd

---
always_allow_html: yes
output: 
  pdf_document:
    keep_tex: yes
---

```{r}
test
```

ui.r

fluidPage(
 downloadButton('downloadReport')
)
1
Shouldn't you be using pdf_document() instead of html_document()? Have you checked what the contents of input.pdf look like after it is rendered (with, e.g., a text editor)?r2evans
Yes, I should be using pdf_document(). It appears some additional LaTex packages were needed as well. It works now. Thanks.JL82559

1 Answers

1
votes
---
output:
  pdf_document: default
  html_document: default
  word_document: default
allow_html: yes
---

Use the above allow_html: yes , it would convert the HTML plots into static plots and would work in PDF without any problem.