% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/get_pdf_image.R
\name{get_pdf_image}
\alias{get_pdf_image}
\title{Obtain Image from a PDF Document}
\usage{
get_pdf_image(
  input,
  output = tempfile(fileext = ".jpg"),
  page = 1,
  width = 300,
  depth = 8,
  quality = 70,
  timeout = 120
)
}
\arguments{
\item{input}{'character' string.
File path to the PDF document.}

\item{output}{'character' string.
File path for the JPEG image to write. If the path lacks a \code{.jpg} or \code{.jpeg}
extension, \code{.jpg} is appended. Defaults to a temporary file.}

\item{page}{'integer' number.
Page number to render. Defaults to 1 (the cover page).}

\item{width}{'integer' number.
Output image width in pixels. Height is set automatically to preserve the
page's aspect ratio. Defaults to 300.}

\item{depth}{'integer' number.
Image color depth, either 8 or 16. Defaults to 8.}

\item{quality}{'integer' number between 0 and 100.
JPEG compression quality. Defaults to 70.}

\item{timeout}{'numeric' number.
Maximum time, in seconds, to allow the PDF page to render before the operation is aborted.}
}
\value{
Returns the path to the image file, invisibly.
}
\description{
Render a single page of a PDF document to a JPEG image. Typically
used to capture a publication's cover (the first page) as a thumbnail.
Requires that the \pkg{pdftools}, \pkg{magick}, and \pkg{callr} packages are
available.
}
\details{
The selected page is rendered at a resolution computed from the
requested output width (to avoid rasterizing a needlessly large image),
resized with a high-quality Lanczos filter while preserving aspect ratio,
flattened onto a white background, converted to an sRGB JPEG at the given
color depth, and stripped of metadata before being written.

The Poppler-backed reads and the page rasterization are run in a child
process, so a native crash on a problematic PDF (which cannot be caught with
\code{tryCatch}) surfaces here as a normal R error instead of taking down the
session or aborting a batch run.
}
\examples{
input <- system.file("extdata", "test.pdf", package = "inlpubs")
path <- get_pdf_image(input)

unlink(path)
}
\seealso{
\code{\link{add_content}} to add cover images to the \pkg{inlpubs} package.
}
\author{
J.C. Fisher, U.S. Geological Survey, Idaho Water Science Center
}
