【发布时间】:2021-01-08 00:42:02
【问题描述】:
我正在尝试将一组用 Rmarkdown 编写并使用xaringan::moon_reader 以 HTML 格式输出的幻灯片转换为 PDF,并使用pagedown::chrome_print() 转换为 PDF。
问题是,转换后的 PDF 缺少其标题页以及整个幻灯片中的随机页面。我尝试使用 Chrome 和其他浏览器手动打印 HTML 文件以尝试保存为 PDF,但它们缺少相同的页面。
对于如何在不丢失任何页面的情况下导出为 PDF 的任何建议,我都愿意接受。不一定非要chrome_print(),只要幻灯片可以成功导出为PDF即可。
这是幻灯片的可重现伪代码:
---
title: document_title
author: author_name
output:
xaringan::moon_reader:
css: [default, metropolis, metropolis-fonts]
lib_dir: libs
nature:
ratio: '4:3'
highlightStyle: github
highlightLines: true
countIncrementalSlides: false
editor_options:
chunk_output_type: console
---
count: false
<style>
.center2 {
margin: 0;
position: absolute;
top: 50%;
left: 50%;
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
pre.sourceCode {
max-height: 200px;
overflow-y: auto;
}
/*
.remark-slide-number {
position: inherit;
}
.remark-slide-number .progress-bar-container {
position: absolute;
bottom: 0;
height: 4px;
display: block;
left: 0;
right: 0;
}
.remark-slide-number .progress-bar {
height: 100%;
background-color: blue;
}
*/
</style>
# only using two backticks for codechunks in rmd to escape ending the codeblock on stackoverflow
``{css, echo=FALSE}
@media print {
.has-continuation {
display: block !important;
}
}
``
``{r setup, include=FALSE}
options(htmltools.dir.version = FALSE)
library(knitr)
opts_chunk$set(
fig.align="center",
fig.height=4,
dpi=300,
cache=T ,
echo=F
)
library(tidyverse)
library(hrbrthemes)
library(fontawesome)
``
count: true
# Slide 1
</br>
.font130[
1. Content 1
2. Content 2
]
---
count: false
# Slide 2
</br>
.font130[
Content for slide 2
]
---
``{r gen_pdf, include = FALSE, cache = FALSE, eval = TRUE}
pagedown::chrome_print("slides.html", output = "slides.pdf")
``
我们在整个文档中都有count:true 和count: false,但它似乎与页面是否丢失无关。
非常感谢您!
【问题讨论】:
标签: r-markdown r-package html-to-pdf pagedown xaringan