简体   繁体   English

使用 pagedown::chrome_print(R 包)将页码添加到 pdf?

[英]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 还提供以下值: datetitleurlpageNumbertotalPages

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.

相关问题 使用 chrome_print 将 pagedown html_resume 编织为 pdf 会产生错误 - knit pagedown html_resume to pdf with chrome_print produces error R Markdown:使用 pagedown::chrome_print 打印可反应的表格会导致一些不可读的行 - R Markdown: Printing reactable tables with pagedown::chrome_print causes some unreadable rows 我无法从 shiny 应用程序创建一个 pagedown::chrome_print pdf output 应用程序,该应用程序接受参数输入并呈现 Rmarkdown - I'm failing to create a pagedown::chrome_print pdf output from a shiny app which takes parameter inputs and renders the Rmarkdown 为什么 pagedown::chrome_print() 将纯色 html 元素转换为渐变? - Why is pagedown::chrome_print() converting a solid color html element to a gradient? 如何在 R 中使用 pagedown 和 kable 打印表格后跟分页符 - How to use pagedown and kable in R to print a table followed by a page break 如何使用 pagedown package 模板在任何地方添加目录? - How to add table of contents in any place using pagedown package template? 在 R pagedown package 中编辑边距框大小 - Editing margin box sizes in R pagedown package 使用 xml2 从 HTML 打印 PDF 时删除 href 和/或停用锚定链接,并使用 R 进行分页 - Remove href and/or deactivate anchored links when printing a PDF from HTML using xml2 and pagedown with R 使用 R pagedown package 将网页提取为 PDF,而不会弹出窗口和 cookie 警告 - Using R pagedown package to extract webpages as PDFs without pop-ups and cookie warnings 使用 pagedown 创建的 xaringan PDF 中不需要的边距 - Unwanted margins in xaringan PDF created using pagedown
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM