bookmarks {xmpdf} | R Documentation |
Set/get pdf bookmarks
Description
get_bookmarks()
gets pdf bookmarks from a file.
set_bookmarks()
sets pdf bookmarks for a file.
Usage
get_bookmarks(filename, use_names = TRUE)
get_bookmarks_pdftk(filename, use_names = TRUE)
get_bookmarks_pdftools(filename, use_names = TRUE)
set_bookmarks(bookmarks, input, output = input)
set_bookmarks_pdftk(bookmarks, input, output = input)
set_bookmarks_gs(bookmarks, input, output = input)
Arguments
filename |
Filename(s) (pdf) to extract bookmarks from. |
use_names |
If |
bookmarks |
A data frame with bookmark information with the following columns:
|
input |
Input pdf filename. |
output |
Output pdf filename. |
Details
get_bookmarks()
will try to use the following helper functions in the following order:
-
get_bookmarks_pdftk()
which wrapspdftk
command-line tool -
get_bookmarks_pdftools()
which wrapspdftools::pdf_toc()
set_bookmarks()
will try to use the following helper functions in the following order:
-
set_bookmarks_gs()
which wrapsghostscript
command-line tool -
set_bookmarks_pdftk()
which wrapspdftk
command-line tool
Value
get_bookmarks()
returns a list of data frames with bookmark info (see bookmarks
parameter for details about columns) plus "total_pages", "filename", and "title" attributes.
NA
values in the data frame indicates that the backend doesn't report information about this pdf feature.
set_bookmarks()
returns the (output) filename invisibly.
Known limitations
-
get_bookmarks_pdftk()
doesn't report information about bookmarks color, fontface, and whether the bookmarks should start open or closed. -
get_bookmarks_pdftools()
doesn't report information about bookmarks page number, color, fontface, and whether the bookmarks should start open or closed. -
set_bookmarks_gs()
supports most bookmarks features including color and font face but only action supported is to view a particular page. -
set_bookmarks_pdftk()
only supports setting the title, page number, and level of bookmarks.
See Also
supports_get_bookmarks()
, supports_set_bookmarks()
, supports_gs()
, and supports_pdftk()
to detect support for these features. For more info about the pdf bookmarks feature see https://opensource.adobe.com/dc-acrobat-sdk-docs/library/pdfmark/pdfmark_Basic.html#bookmarks-out.
Examples
# Create 2-page pdf using `pdf)` and add some bookmarks to it
if (supports_set_bookmarks() && supports_get_bookmarks() && 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(get_bookmarks(f)[[1]])
bookmarks <- data.frame(title = c("Page 1", "Page 2"), page = c(1, 2))
set_bookmarks(bookmarks, f)
print(get_bookmarks(f)[[1]])
unlink(f)
}