使用R中的pdf()图形设备创建PDF时,可以使用title =参数轻松添加标题元数据到pdf()。但是没有明显的方法可以添加作者。
在R中查看pdf()的代码,关键似乎是C函数C_PDF,它显然没有作者参数,这超出了我的破解能力。还有其他方法,比将我的图形输出编织成LaTeX创建的PDF更方便,包括作者信息并保存我们以后手动操作吗?
.External(C_PDF, file, old$paper, old$family, old$encoding,
old$bg, old$fg, old$width, old$height, old$pointsize,
onefile, old$pagecentre, old$title, old$fonts, version[1L],
version[2L], old$colormodel, old$useDingbats, old$useKerning,
old$fillOddEven, old$compress)
我对此没有太大的希望,因为this broader question没有令人满意的基于语言的答案......
答案 0 :(得分:4)
以下是使用these filetypes获取和设置任何ExifTool的Exif元数据的几个函数。
获取元数据:
getexif <- function(file, exiftool='exiftool.exe', opts=NULL,
intern=TRUE, simplify=FALSE) {
# file: the file to be updated
# exiftool: the path to the ExifTool binary
# opts: additional arguments to ExifTool (optional)
# intern: should a named vector of metadata be returned? (bool)
# simplify: if intern==TRUE, should the results be returned as a named
# vector (TRUE) or as a data.frame (FALSE)?
arg <- c(opts, normalizePath(file))
if(intern) {
exif <- system2(normalizePath(exiftool), args=arg, stdout=TRUE)
exif <- do.call(rbind, strsplit(exif, ' +: +', perl=T))
row.names(exif) <- exif[, 1]
exif[, 2, drop=simplify]
} else {
system2(normalizePath(exiftool), args=arg, stdout='')
}
}
设置元数据:
setexif <- function(file, metadata, exiftool='exiftool.exe') {
# file: the file to be updated
# metadata: a named character vector or list containing metadata
# exiftool: the path to the ExifTool binary
exif <- sprintf('-%s="%s"', names(metadata), metadata)
system2(exiftool, args=c(exif, file))
}
这是一个例子
pdf(f <- tempfile(fileext='.pdf'))
plot(runif(10))
dev.off()
toolpath <- 'c:/software/exiftool(-k).exe'
setexif(f, c(title = "foo", subject='bar', author = "Me"), toolpath)
getexif(f, toolpath)
## [,1]
## ExifTool Version Number "9.64"
## File Name "file237c6f8d4dac.pdf"
## Directory "C:/Users/john/AppData/Local/Temp/RtmpSGqI6O"
## File Size "7.8 kB"
## File Modification Date/Time "2014:06:17 10:50:22+10:00"
## File Access Date/Time "2014:06:17 10:50:22+10:00"
## File Creation Date/Time "2014:06:17 10:50:20+10:00"
## File Permissions "rw-rw-rw-"
## File Type "PDF"
## MIME Type "application/pdf"
## PDF Version "1.4"
## Linearized "No"
## Create Date "2014:06:17 10:50:20"
## Modify Date "2014:06:17 10:50:20"
## Producer "R 3.1.0"
## Creator "R"
## Page Count "1"
## XMP Toolkit "Image::ExifTool 9.64"
## Subject "bar"
## Title "foo"
## Author "Me"