n_pages {xmpdf}R Documentation

Get number of pages in a document

Description

n_pages() returns the number of pages in the (pdf) file(s).

Usage

n_pages(filename, use_names = TRUE)

n_pages_exiftool(filename, use_names = TRUE)

n_pages_qpdf(filename, use_names = TRUE)

n_pages_pdftk(filename, use_names = TRUE)

n_pages_gs(filename, use_names = TRUE)

Arguments

filename

Character vector of filenames.

use_names

If TRUE (default) use filename as the names of the result.

Details

n_pages() will try to use the following helper functions in the following order:

  1. n_pages_qpdf() which wraps qpdf::pdf_length()

  2. n_pages_exiftool() which wraps exiftool command-line tool

  3. n_pages_pdftk() which wraps pdftk command-line tool

  4. n_pages_gs() which wraps ghostscript command-line tool

Value

An integer vector of number of pages within each file.

See Also

supports_n_pages() detects support for this feature.

Examples

if (supports_n_pages() && require("grid", quietly = TRUE)) {
  f <- tempfile(fileext = ".pdf")
  pdf(f, onefile = TRUE)
  grid.text("Page 1")
  grid.newpage()
  grid.text("Page 2")
  invisible(dev.off())
  print(n_pages(f))
  unlink(f)
}

[Package xmpdf version 0.2.1 Index]