使用新的Adobe Acrobat 11.0将.Rmd转换为PDF格式的PDF

时间:2016-08-24 18:11:54

标签: r pdf shiny r-markdown

有r Shiny app和Rmd文件。尝试使用downloadHandler()下载,但收到Adobe Acrobat错误说:

“Acrobat无法打开'rstudio-iV1460.pdf',因为它不是受支持的文件类型,或者因为文件已损坏(例如,它是作为电子邮件附件发送的,并且未正确解码)。 “

发现这是因为使用Acrobat v11.0并且需​​要确保文档头部格式为%PDF字符串。

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

问题:我在哪里放置此%PDF以及如何解决此问题?我把它放在Rmd文档或tex文档中吗?

以下是我在我的r Shiny应用程序中使用Rmd制作pdf的方法:

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 个答案:

答案 0 :(得分:1)

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

使用上面的 allow_html:是,它会将HTML图转换为静态图,并且可以在 PDF 中正常工作。