[英]Add page numbers to pdf using pagedown::chrome_print (R package)?
I am using pagedown::chrome_print()
to convert slidy presentations created with Rmarkdown to pdf -- it does a better job than saving as PDF from Chrome.我正在使用pagedown::chrome_print()
将使用 Rmarkdown 创建的幻灯片演示文稿转换为 pdf - 它比从 Chrome 保存为 PDF 做得更好。 However, despite studying the help file, I cannot figure out how to add page numbers.然而,尽管研究了帮助文件,我还是不知道如何添加页码。 Is there a way to do this?有没有办法做到这一点?
(Note that pagedown here refers to the R package, not the JavaScript markdown previewer.) (注意这里的 pagedown 指的是 R 包,而不是 JavaScript markdown 预览器。)
Sorry if the help page is not clear on this point.抱歉,如果帮助页面在这一点上不清楚。
It is possible to pass header/footer options to Chrome using pagedown::chrome_print()
.可以使用pagedown::chrome_print()
将页眉/页脚选项传递给 Chrome。
These options are the ones defined by the Chrome DevTools Protocol for the Page.printToPDF method .这些选项是 Chrome DevTools 协议为Page.printToPDF 方法定义的选项。
You can customise the header and the footer with an HTML template.您可以使用 HTML 模板自定义页眉和页脚。 Chrome also offers the following values: date
, title
, url
, pageNumber
and totalPages
. Chrome 还提供以下值: date
、 title
、 url
、 pageNumber
和totalPages
。
Following the explanations on this help page, here is an example to print the page numbers:按照此帮助页面上的说明,以下是打印页码的示例:
library(htmltools)
footer <- div(
style = "font-size: 8pt; text-align: right; width: 100%; padding-right: 12pt;",
span(class = "pageNumber"), "/", span(class = "totalPages")
)
pagedown::chrome_print(
"slidy.Rmd",
options = list(
landscape = TRUE,
displayHeaderFooter = TRUE,
footerTemplate = format(footer, indent = FALSE),
marginTop = 0,
marginBottom = 0.4
)
)
I got it to work with a custom CSS file.我让它与自定义 CSS 文件一起使用。 I created a file called custom.css
and included in that file was我创建了一个名为custom.css
的文件并包含在该文件中
@page {
@bottom-right {
content: counter(page);
}
}
Then I used that along with the other pagedown defaults with a header like this然后我将它与其他 pagedown 默认值一起使用,并带有这样的标题
title: "My Report"
output:
pagedown::html_paged:
css: ["custom.css", "default-fonts", "default"]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.