cat_bookmarks {xmpdf} | R Documentation |
Concatenate pdf bookmarks
Description
cat_bookmarks()
concatenates a list of bookmarks
into a single bookmarks data frame while updating the page numbers.
Useful if wanting to concatenate multiple pdf files together and
would like to preserve the bookmarks information.
Usage
cat_bookmarks(
l,
method = c("flat", "filename", "title"),
open = NA,
color = NA_character_,
fontface = NA_character_
)
Arguments
l |
A list of bookmark data frames as returned by |
method |
If "flat" simply concatenate the bookmarks while updating page numbers. If "filename" place each file's bookmarks a level under a new bookmark matching the (base)name of the filename and then concatenate the bookmarks while updating page numbers. If "title" place each file's bookmarks a level under a new bookmark matching the title of the file and then concatenate the bookmarks while updating page numbers. |
open |
If |
color |
If |
fontface |
If |
Value
A data frame of bookmark data (as suitable for use with set_bookmarks()
).
A "total_pages" attribute will be set for the theoretical total pages of
the concatenated document represented by the concatenated bookmarks.
See Also
get_bookmarks()
and set_bookmarks()
for setting bookmarks.
cat_pages()
for concatenating pdf files together.
Examples
if (supports_get_bookmarks() &&
supports_set_bookmarks() &&
supports_pdftk() &&
require("grid", quietly = TRUE)) {
# Create two different two-page pdf files
make_pdf <- function(f, title) {
pdf(f, onefile = TRUE, title = title)
grid.text(paste(title, "Page 1"))
grid.newpage()
grid.text(paste(title, "Page 2"))
invisible(dev.off())
}
f1 <- tempfile(fileext = "_doc1.pdf")
on.exit(unlink(f1))
make_pdf(f1, "Document 1")
f2 <- tempfile(fileext = "_doc2.pdf")
on.exit(unlink(f2))
make_pdf(f2, "Document 2")
# Add bookmarks to the two two-page pdf files
bookmarks <- data.frame(title = c("Page 1", "Page 2"),
page = c(1L, 2L))
set_bookmarks(bookmarks, f1)
set_bookmarks(bookmarks, f2)
l <- get_bookmarks(c(f1, f2))
print(l)
bm <- cat_bookmarks(l, method = "flat")
cat('\nmethod = "flat":\n')
print(bm)
bm <- cat_bookmarks(l, method = "filename")
cat('\nmethod = "filename":\n')
print(bm)
bm <- cat_bookmarks(l, method = "title")
cat('\nmethod = "title":\n')
print(bm)
# `cat_bookmarks()` is useful for setting concatenated pdf files
# created with `cat_pages()`
if (supports_cat_pages()) {
fc <- tempfile(fileext = "_cat.pdf")
on.exit(unlink(fc))
cat_pages(c(f1, f2), fc)
set_bookmarks(bm, fc)
unlink(fc)
}
unlink(f1)
unlink(f2)
}