【问题标题】:Convert .Rmd to PDF in Shiny with new Adobe Acrobat 11.0使用新的 Adob​​e Acrobat 11.0 在 Shiny 中将 .Rmd 转换为 PDF
【发布时间】:2017-01-01 00:02:03
【问题描述】:

有 r Shiny 应用程序和 Rmd 文件。尝试使用 downloadHandler() 下载,但收到 Adob​​e 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 的方式:

服务器.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)
  }
)
}

输入.Rmd

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

```{r}
test
```

ui.r

fluidPage(
 downloadButton('downloadReport')
)

【问题讨论】:

  • 您不应该使用pdf_document() 而不是html_document() 吗?您是否检查过 input.pdf内容 在渲染后的样子(例如,使用文本编辑器)?
  • 是的,我应该使用 pdf_document()。似乎还需要一些额外的 LaTex 包。现在可以了。谢谢。

标签: r pdf shiny r-markdown


【解决方案1】:
---
output:
  pdf_document: default
  html_document: default
  word_document: default
allow_html: yes
---

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

【讨论】:

    猜你喜欢
    • 2016-09-26
    • 2019-01-20
    • 1970-01-01
    • 1970-01-01
    • 2014-10-29
    • 1970-01-01
    • 2015-10-20
    • 2011-06-16
    • 2018-12-06
    相关资源
    最近更新 更多