How to extract images from a PPT and save them into separate media files

85 Views Asked by At

I have a series of ppt files that contain jpg images. I need to extract each of these images and save them as image file (jpeg)

I am clueless on how to go about this. I can open the ppt file and see the object contains the media, but I dont know how to extract these into single object and save them as jpeg.

doc <- read_pptx(paste0(wd, "/", files[1]))
content <- pptx_summary(doc)
content

view of content

I can see that R detects the images but I need to save them into separate files. Any idea?

Thanks!

1

There are 1 best solutions below

1
On

this should help:

example_pptx <- system.file(package = "officer","doc_examples/example.pptx")

doc <- read_pptx(example_pptx)

content <- pptx_summary(doc)

image_row <- content[content$content_type %in% "image", ]

media_file <- image_row$media_file

png_file <- tempfile(fileext = ".png")

media_extract(doc, path = media_file, target = png_file)