Skip to contents

get_docinfo() gets pdf document info from a file. set_docinfo() sets pdf document info for a file.

Usage

get_docinfo(filename, use_names = TRUE)

get_docinfo_pdftools(filename, use_names = TRUE)

get_docinfo_exiftool(filename, use_names = TRUE)

set_docinfo_exiftool(docinfo, input, output = input)

get_docinfo_pdftk(filename, use_names = TRUE)

set_docinfo(docinfo, input, output = input)

set_docinfo_gs(docinfo, input, output = input)

set_docinfo_pdftk(docinfo, input, output = input)

Arguments

filename

Filename(s) (pdf) to extract info dictionary entries from.

use_names

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

docinfo

A "docinfo" object (as returned by docinfo() or get_docinfo()).

input

Input pdf filename.

output

Output pdf filename.

Value

docinfo() returns a "docinfo" R6 class. get_docinfo() returns a list of "docinfo" R6 classes. set_docinfo() returns the (output) filename invisibly.

Details

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

  1. get_docinfo_pdftk() which wraps pdftk command-line tool

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

  3. get_docinfo_pdftools() which wraps pdftools::pdf_info()

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

  1. set_docinfo_exiftool() which wraps exiftool command-line tool

  2. set_docinfo_gs() which wraps ghostscript command-line tool

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

Known limitations

  • Whenever ghostscript's pdfwrite device is used to write a pdf it regenerates the entire XMP metadata packet from the current documentation info dictionary, discarding any existing XMP metadata that isn't one of the eight standard documentation info entries (e.g. Creative Commons or IPTC XMP tags set via set_xmp() will be silently erased, not merely left alone or updated). This affects set_docinfo_gs() and set_bookmarks_gs(). If you need both custom XMP metadata and set_docinfo_gs()/set_bookmarks_gs(), call set_xmp() after them, never before.

  • Some pdf viewers will also preferentially use a previously set document title from XMP metadata instead of the title set in the documentation info dictionary entry.

  • Old metadata information is usually not deleted from the pdf file by these operations. If deleting the old metadata is important one may want to try qpdf::pdf_compress(input, linearize = TRUE).

  • get_docinfo_exiftool() will "widen" datetimes to second precision.

  • get_docinfo_exiftool() reports arbitrary (non-standard) info dictionary keys under a "sanitized" name rather than their literal name in the pdf, since exiftool itself rewrites any character it doesn't allow in a tag name to _ (e.g. a literal key PTEX.Fullbanner is reported as PTEX_Fullbanner) and prepends Tag to a key that doesn't start with a letter (e.g. a literal key 1Key is reported as Tag1Key). Writing this "sanitized" key back out (with any backend, including set_docinfo_exiftool()) creates a new entry under the sanitized name rather than updating the original one.

  • get_docinfo_pdftools()'s datetimes may not accurately reflect the embedded datetimes.

  • set_docinfo_pdftk() may not correctly handle documentation info entries with newlines in them.

  • In general arbitrary (non-standard) info dictionary keys can start with a letter and otherwise contain only letters, digits, underscores, and hyphens.

    • set_docinfo_exiftool() only allows these.

    • set_docinfo_gs() also allows periods.

    • set_docinfo_pdftk() is the most permissive: any Latin-1-representable key without control characters (e.g. a newline) is allowed.

See also

docinfo() for more information about the documentation info objects. supports_get_docinfo(), supports_set_docinfo(), supports_gs(), and supports_pdftk() to detect support for these features. For more info about the pdf document info dictionary see https://opensource.adobe.com/dc-acrobat-sdk-docs/library/pdfmark/pdfmark_Basic.html#document-info-dictionary-docinfo.

Examples

if (supports_set_docinfo() && supports_get_docinfo() && 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())

  cat("\nInitial documentation info:\n\n")
  d <- get_docinfo(f)[[1]]
  print(d)

  d <- update(d,
              author = "John Doe",
              title = "Two Boring Pages",
              keywords = c("R", "xmpdf"))
  set_docinfo(d, f)

  cat("\nDocumentation info after setting it:\n\n")
  print(get_docinfo(f)[[1]])

  unlink(f)
}
#> 
#> Initial documentation info:
#> 
#> Author: NULL
#> CreationDate: 2026-08-25T13:12:20
#> Creator: R
#> Producer: R 4.6.1
#> Title: R Graphics Output
#> Subject: NULL
#> Keywords: NULL
#> ModDate: 2026-08-25T13:12:20
#> 
#> Documentation info after setting it:
#> 
#> Author: John Doe
#> CreationDate: 2026-08-25T13:12:20
#> Creator: R
#> Producer: R 4.6.1
#> Title: Two Boring Pages
#> Subject: NULL
#> Keywords: R, xmpdf
#> ModDate: 2026-08-25T13:12:20