【问题标题】:Include Viewer-output in PDF在 PDF 中包含查看器输出
【发布时间】:2017-04-16 18:06:01
【问题描述】:

我有一个 R-Markdown 文件,其中包含一些我想编织成 pdf 的 HTML 输出。我的问题是,有没有办法捕获查看器的输出并自动包含它。

例如,考虑以下 MWE:

---
title: "Include Viewer in PDF"
author: "Myself"
date: "today"
output:
  pdf_document: default
always_allow_html: yes
---
```{r}
library(stringr)
str_view("hello world", "o\\s[sw]")
```

如果我使用 knit to HTML,结果会正确显示:

如果我使用 knit to PDF,则根本不会显示结果(因为我使用了 always_allow_html: yes,但是如果我排除了该规范,则会收到错误消息: Error: Functions that produce HTML output found in document targeting latex output. ...):

有什么想法吗?

【问题讨论】:

    标签: pdf r-markdown


    【解决方案1】:

    好的,我找到了解决方案。感谢this question,它将我引向webshot-library。

    所以安装webshot 并在必要时运行webshot::install_phantomjs()。现在 knitr 可以自动截取 Viewer 的截图。

    上面的 PDF 代码现在产生:

    【讨论】:

    • 不幸的是,这对我不起作用。我得到的输出非常小,几乎不可读。有什么方法可以控制输出大小?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多