Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

pdf_render_page

Render / Convert PDF


Description

High quality conversion of pdf page(s) to png, jpeg or tiff format, or render into a raw bitmap array for further processing in R.

Usage

pdf_render_page(
  pdf,
  page = 1,
  dpi = 72,
  numeric = FALSE,
  antialias = TRUE,
  opw = "",
  upw = ""
)

pdf_convert(
  pdf,
  format = "png",
  pages = NULL,
  filenames = NULL,
  dpi = 72,
  antialias = TRUE,
  opw = "",
  upw = "",
  verbose = TRUE
)

poppler_config()

Arguments

pdf

file path or raw vector with pdf data

page

which page to render

dpi

resolution (dots per inch) to render

numeric

convert raw output to (0-1) real values

antialias

enable antialiasing. Must be "text" or "draw" or TRUE (both) or FALSE (neither).

opw

owner password

upw

user password

format

string with output format such as "png" or "jpeg". Must be equal to one of poppler_config()$supported_image_formats.

pages

vector with one-based page numbers to render. NULL means all pages.

filenames

vector of equal length to pages with output filenames. May also be a format string which is expanded using pages and format respectively.

verbose

print some progress info to stdout

See Also

Other pdftools: pdf_ocr_text(), pdftools, qpdf

Examples

# Rendering should be supported on all platforms now
# convert few pages to png
file.copy(file.path(Sys.getenv("R_DOC_DIR"), "NEWS.pdf"), "news.pdf")
pdf_convert("news.pdf", pages = 1:3)

# render into raw bitmap
bitmap <- pdf_render_page("news.pdf")

# save to bitmap formats
png::writePNG(bitmap, "page.png")
jpeg::writeJPEG(bitmap, "page.jpeg")
webp::write_webp(bitmap, "page.webp")

# Higher quality
bitmap <- pdf_render_page("news.pdf", page = 1, dpi = 300)
png::writePNG(bitmap, "page.png")

# slightly more efficient
bitmap_raw <- pdf_render_page("news.pdf", numeric = FALSE)
webp::write_webp(bitmap_raw, "page.webp")

# Cleanup
unlink(c('news.pdf', 'news_1.png', 'news_2.png', 'news_3.png',
 'page.jpeg', 'page.png', 'page.webp'))

pdftools

Text Extraction, Rendering and Converting of PDF Documents

v3.0.1
MIT + file LICENSE
Authors
Jeroen Ooms [aut, cre] (<https://orcid.org/0000-0002-4035-0289>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.