You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Quarto文本句中插入PDF/CSV下载按钮?

在Quarto文本中嵌入下载按钮的实现方法

需求说明

需要在Quarto文档的句子中间插入可下载PDF/CSV文件的小型按钮,按钮需被文本环绕,而非放置在导航栏或侧边栏。可复现的基础代码如下:

---
title: "Download button in text Quarto"
format: 
  html:
    code-fold: true
engine: knitr
---

我希望在这个位置插入一个可下载PDF或CSV文件的按钮,让按钮被文本环绕。

方法1:使用downloadthis包实现

downloadthis包可以生成标准下载按钮,通过自定义CSS调整样式后,能完美嵌入文本流中:

  1. 安装并加载包:
install.packages("downloadthis")
library(downloadthis)
  1. 修改Quarto文档内容,插入按钮代码并引入自定义样式:
---
title: "Download button in text Quarto"
format: 
  html:
    code-fold: true
    css: styles.css # 引入自定义样式文件
engine: knitr
---

我希望在这个位置`r download_file(
  path = "your_target_file.pdf", # 替换为你的文件路径
  button_label = "下载PDF",
  button_type = "default",
  has_icon = TRUE,
  icon = "fa-download"
)`插入一个可下载PDF或CSV文件的按钮,让按钮被文本环绕。
  1. 创建styles.css文件,添加以下样式让按钮适配文本嵌入场景:
.downloadthis-button {
  padding: 2px 8px;
  font-size: 0.8em;
  vertical-align: middle;
  margin: 0 4px;
}

方法2:直接使用HTML按钮(无依赖更灵活)

如果不想依赖R包,直接用HTML代码自定义按钮样式,完全适配文本流:

---
title: "Download button in text Quarto"
format: 
  html:
    code-fold: true
engine: knitr
---

我希望在这个位置<button style="padding:2px 8px; font-size:0.8em; vertical-align:middle; margin:0 4px; border:1px solid #ccc; border-radius:4px; background:#f5f5f5;" href="your_target_file.pdf" download>下载PDF</button>插入一个可下载PDF或CSV文件的按钮,让按钮被文本环绕。

也可以用带样式的链接模拟按钮效果:

---
title: "Download button in text Quarto"
format: 
  html:
    code-fold: true
engine: knitr
---

我希望在这个位置<a style="display:inline-block; padding:2px 8px; font-size:0.8em; vertical-align:middle; margin:0 4px; border:1px solid #ccc; border-radius:4px; text-decoration:none; color:#333; background:#f5f5f5;" href="your_target_file.pdf" download>下载PDF</a>插入一个可下载PDF或CSV文件的按钮,让按钮被文本环绕。

内容的提问来源于stack exchange,提问作者Quinten

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 01:25:25