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) usefilenameas the names of the result.- docinfo
A "docinfo" object (as returned by
docinfo()orget_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:
get_docinfo_pdftk()which wrapspdftkcommand-line toolget_docinfo_exiftool()which wrapsexiftoolcommand-line toolget_docinfo_pdftools()which wrapspdftools::pdf_info()
set_docinfo() will try to use the following helper functions in the following order:
set_docinfo_exiftool()which wrapsexiftoolcommand-line toolset_docinfo_gs()which wrapsghostscriptcommand-line toolset_docinfo_pdftk()which wrapspdftkcommand-line tool
Known limitations
Whenever
ghostscript'spdfwritedevice 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 viaset_xmp()will be silently erased, not merely left alone or updated). This affectsset_docinfo_gs()andset_bookmarks_gs(). If you need both custom XMP metadata andset_docinfo_gs()/set_bookmarks_gs(), callset_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, sinceexiftoolitself rewrites any character it doesn't allow in a tag name to_(e.g. a literal keyPTEX.Fullbanneris reported asPTEX_Fullbanner) and prependsTagto a key that doesn't start with a letter (e.g. a literal key1Keyis reported asTag1Key). Writing this "sanitized" key back out (with any backend, includingset_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