-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxaringan_to_powerpoint.R
62 lines (43 loc) · 1.2 KB
/
xaringan_to_powerpoint.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#' ############################
#' load libraries and set seed
#' ############################
library(tidyverse)
library(pagedown)
library(pdftools)
library(glue)
library(rmarkdown)
#' ############################
#' convert HTML slides to PPTX slides
#' see:
#'
#' https://github.com/gadenbuie/xaringan2powerpoint
#'
#' ############################
#slides_html <- "slides.html"
# "print" HTML to PDF
#pagedown::chrome_print(input = "slides.html", output = "slides.pdf")
# how many pages?
pages <- pdftools::pdf_info("slides.pdf")$pages
# set filenames
filenames <- sprintf("slides/slides_%02d.png", 1:pages)
# create slides/ and convert PDF to PNG files
dir.create("slides")
pdftools::pdf_convert("slides.pdf", filenames = filenames, dpi = 480)
# Template for markdown containing slide images
slide_images <- glue::glue("
---
![]({filenames}){{width=100%}}
")
slide_images <- paste(slide_images, collapse = "\n")
# R Markdown -> powerpoint presentation source
md <- glue::glue("
---
output:
powerpoint_presentation:
reference_doc: blankslide16-9.pptx
---
{slide_images}
")
cat(md, file = "slides_powerpoint.rmd")
# Render Rmd to powerpoint
rmarkdown::render("slides_powerpoint.rmd") ## powerpoint!