rendering {pdftools} | R Documentation |
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 |
opw |
owner password |
upw |
user password |
format |
string with output format such as |
pages |
vector with one-based page numbers to render. |
filenames |
vector of equal length to |
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")
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'))