pdimg_images: pdimg_images

View source: R/pdimg_images.R

pdimg_imagesR Documentation

pdimg_images

Description

extract images from a pdf

Usage

pdimg_images(paths, base_dir = NULL, ...)

Arguments

paths

(character) path to a pdf, required

base_dir

(character) the base path to collect files into. if NULL (default), we use a temp directory

...

additional command line args passed on to pdfimages. See pdimg_help() for docs

Value

data.frames of metadata on images in the pdf. if the path is not found or the path is found but no images are found, then a warning is thrown and a zero row data.frame is returned

Note

by default we use temp dir to store extracted images - at the end of an R session these are cleaned up (deleted). to store images after the R session ends use base_dir

Examples

# images found
x <- system.file("examples/BachmanEtal2020.pdf", package="pdfimager")
res <- pdimg_images(x)
res
res[[1]]$path
file.exists(res[[1]]$path[1])

z <- system.file("examples/Tierney2017JOSS.pdf", package="pdfimager")
pdimg_images(z)

# change base directory to hold extracted images
x <- system.file("examples/BachmanEtal2020.pdf", package="pdfimager")
dir <- file.path(tempdir(), "bluetree")
res <- pdimg_images(x, base_dir = dir)

# many at once
pdimg_images(c(x, z))
## pass custom dir to each path
pdimg_images(c(x, z), file.path(tempdir(), "pepperjackcheese"))

# no images found, but there are actually images 
d <- system.file("examples/LahtiEtal2017.pdf", package="pdfimager")
pdimg_images(d)

# no images found, and there really are no images
w <- system.file("examples/White2015.pdf", package="pdfimager")
pdimg_images(w)

# path not found
pdimg_images("foo-bar")

# only gets overlayed smaller images on plots, doesn't get plots
# themselves
g <- system.file("examples/vanGemert2018.pdf", package="pdfimager")
pdimg_images(g)

# number of images doesn't match number of rows of metadata
## so we fix internally by removing duplicate files for same image
h <- system.file("examples/SanyalEtal2018.pdf", package="pdfimager")
pdimg_images(h)

# convert to another format - not entirely sure how this works,
# it's not documented
j <- system.file("examples/SanyalEtal2018.pdf", package="pdfimager")
pdimg_images(j, format = "-png")[[1]]$path[1:5]

sckott/pdfimager documentation built on Sept. 15, 2024, 1:19 a.m.