pdf_render_page: Render / Convert PDF

Description Usage Arguments See Also Examples

View source: R/render.R

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

1
2
3
4
5
6
7
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_info

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Rendering should be supported on all platforms now
if(poppler_config()$can_render){

# 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")
}

ropensci/pdftools documentation built on Dec. 10, 2018, 8:04 a.m.