5

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. 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.)

2 Answers 2

6

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().

These options are the ones defined by the Chrome DevTools Protocol for the Page.printToPDF method.

You can customise the header and the footer with an HTML template. Chrome also offers the following values: date, title, url, pageNumber and 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 ) ) 
Sign up to request clarification or add additional context in comments.

2 Comments

Perfect, exactly what I was hoping existed.
Note: at least for my purposes, slidy.Rmd should be slidy.html.
4

I got it to work with a custom CSS file. I created a file called custom.css and included in that file was

@page { @bottom-right { content: counter(page); } } 

Then I used that along with the other pagedown defaults with a header like this

title: "My Report" output: pagedown::html_paged: css: ["custom.css", "default-fonts", "default"] 

5 Comments

Doesn't that produce html output?
Well, pagedown works by making html and then printing to pdf through a web browser. At least that’s how I understand how it works.
I think that's right. So the idea would be to add numbers with html_paged (or perhaps directly through slidy options) and then use chrome_print?
I mean I used exactly this and I got page numbers in my output. Not sure if there was another way.
The problem is that the output that pagedown::html_paged produces is formatted very differently from the slidy_presentation output. I'm going to need to find a way to either add page numbers to the original slidy slides, or perhaps later to the pdf rendered with pagedown::chrome_print.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.