Movatterモバイル変換


[0]ホーム

URL:


xmpdfxmpdf hex sticker

CRAN Status BadgeR-CMD-checkcodecov

Table of Contents

Overview

{xmpdf} provides functions for getting and settingExtensibeMetadata Platform (XMP) metadata in a variety of media file formatsas well as getting and setting PDFdocumentationinfo entries andbookmarks(aka outline aka table of contents).

Installation

remotes::install_github("trevorld/r-xmpdf")

Depending on what you’d like to do you’ll need to install someadditional R packages and/or command-line tools:

Examples

AddXMP/docinfo metadata and bookmarks to a pdf

A simple example where we create a two page pdf usingpdf() and then add XMP metadata, PDF documentation infometadata, and PDF bookmarks to it:

library("xmpdf")# Create a two page pdf using `pdf()`f<-tempfile(fileext =".pdf")pdf(f,onefile =TRUE)grid::grid.text("Page 1")grid::grid.newpage()grid::grid.text("Page 2")invisible(dev.off())# See what default metadata `pdf()` createdget_docinfo(f)[[1]]|>print()
## Author: NULL## CreationDate: 2024-03-27T23:19:05## Creator: R## Producer: R 4.3.3## Title: R Graphics Output## Subject: NULL## Keywords: NULL## ModDate: 2024-03-27T23:19:05
get_xmp(f)[[1]]|>print()
## No XMP metadata found
get_bookmarks(f)[[1]]|>print()
## [1] title    page     level    count    open     color    fontface## <0 rows> (or 0-length row.names)
# Edit PDF documentation infod<-get_docinfo(f)[[1]]|>update(author ="John Doe",subject ="A minimal document to demonstrate {xmpdf} features on",title ="Two Boring Pages",keywords =c("R","xmpdf"))set_docinfo(d, f)get_docinfo(f)[[1]]|>print()
## Author: John Doe## CreationDate: 2024-03-27T23:19:05## Creator: R## Producer: R 4.3.3## Title: Two Boring Pages## Subject: A minimal document to demonstrate {xmpdf} features on## Keywords: R, xmpdf## ModDate: 2024-03-27T23:19:05
# Edit XMP metadatax<-as_xmp(d)|>update(attribution_url ="https://example.com/attribution",date_created =Sys.Date(),spdx_id ="CC-BY-4.0")set_xmp(x, f)get_xmp(f)[[1]]|>print()
##    cc:attributionName := John Doe##    cc:attributionURL := https://example.com/attribution##    cc:license := https://creativecommons.org/licenses/by/4.0/##    dc:creator := John Doe##    dc:description := A minimal document to demonstrate {xmpdf} features on##    dc:rights := © 2024 John Doe. Some rights reserved.##    dc:subject := R, xmpdf##    dc:title := Two Boring Pages##    pdf:Keywords := R, xmpdf##    pdf:Producer := R 4.3.3##    photoshop:Credit := John Doe##    photoshop:DateCreated := 2024-03-27##    x:XMPToolkit := Image::ExifTool 12.40##    xmp:CreateDate := 2024-03-27T23:19:05##    xmp:CreatorTool := R##    xmp:ModifyDate := 2024-03-27T23:19:05##    xmpRights:Marked := TRUE##    xmpRights:UsageTerms := This work is licensed to the public under the Creative Commons##         Attribution 4.0 International license##         https://creativecommons.org/licenses/by/4.0/##    xmpRights:WebStatement := https://creativecommons.org/licenses/by/4.0/
# Edit PDF bookmarksbm<-data.frame(title =c("Page 1","Page 2"),page =c(1,2))set_bookmarks(bm, f)get_bookmarks(f)[[1]]|>print()
##    title page level count open color fontface## 1 Page 1    1     1    NA   NA  <NA>     <NA>## 2 Page 2    2     1    NA   NA  <NA>     <NA>
AddGoogle Images and Creative Commons license XMP metadata to a pngimage

Besides pdf files withexiftool we can also edit the XMPmetadata fora large number ofimage formats including “gif”, “png”, “jpeg”, “tiff”, and “webp”. Inparticular we may be interested in setting the subset ofIPTCPhoto XMP metadata displayed by Google Images as well as embeddingCreative Commonslicense XMP metadata.

library("xmpdf")f<-tempfile(fileext =".png")png(f)grid::grid.text("This is an image!")dev.off()|>invisible()get_xmp(f)[[1]]|>print()
## No XMP metadata found
x<-xmp(attribution_url ="https://example.com/attribution",creator ="John Doe",description ="An image caption",date_created =Sys.Date(),spdx_id ="CC-BY-4.0")print(x,mode ="google_images",xmp_only =TRUE)
##    dc:creator := John Doe## => dc:rights = © 2024 John Doe. Some rights reserved.## => photoshop:Credit = John Doe## X  plus:Licensor (not currently supported by {xmpdf})## => xmpRights:WebStatement = https://creativecommons.org/licenses/by/4.0/
print(x,mode ="creative_commons",xmp_only =TRUE)
## => cc:attributionName = John Doe##    cc:attributionURL := https://example.com/attribution## => cc:license = https://creativecommons.org/licenses/by/4.0/##    cc:morePermissions := NULL## => dc:rights = © 2024 John Doe. Some rights reserved.## => xmpRights:Marked = TRUE## => xmpRights:UsageTerms = This work is licensed to the public under the Creative Commons##         Attribution 4.0 International license##         https://creativecommons.org/licenses/by/4.0/## => xmpRights:WebStatement = https://creativecommons.org/licenses/by/4.0/
set_xmp(x, f)get_xmp(f)[[1]]|>print()
##    cc:attributionName := John Doe##    cc:attributionURL := https://example.com/attribution##    cc:license := https://creativecommons.org/licenses/by/4.0/##    dc:creator := John Doe##    dc:description := An image caption##    dc:rights := © 2024 John Doe. Some rights reserved.##    photoshop:Credit := John Doe##    photoshop:DateCreated := 2024-03-27##    x:XMPToolkit := Image::ExifTool 12.40##    xmpRights:Marked := TRUE##    xmpRights:UsageTerms := This work is licensed to the public under the Creative Commons##         Attribution 4.0 International license##         https://creativecommons.org/licenses/by/4.0/##    xmpRights:WebStatement := https://creativecommons.org/licenses/by/4.0/
Concatenatepdf files and embed concatenated bookmarks
# Create two multi-page pdfs and add bookmarks to themf_a<-tempfile(fileext =".pdf")pdf(f_a,title ="Document A",onefile =TRUE)grid::grid.text("Document A: First Page")grid::grid.newpage()grid::grid.text("Document A: Second Page")dev.off()|>invisible()f_b<-tempfile(fileext =".pdf")pdf(f_b,title ="Document B",onefile =TRUE)grid::grid.text("Document B: First Page")grid::grid.newpage()grid::grid.text("Document B: Second Page")dev.off()|>invisible()bm<-data.frame(title =c("First Page","Second Page"),page =c(1,2))set_bookmarks(bm, f_a)set_bookmarks(bm, f_b)# Concatenate pdfs to a single pdf and add their concatenated bookmarks to itfiles<-c(f_a, f_b)f_cat<-tempfile(fileext =".pdf")cat_pages(files, f_cat)cat_bookmarks(get_bookmarks(files),method ="title")|>set_bookmarks(f_cat)print(get_bookmarks(f_cat)[[1]])
##         title page level count open color fontface## 1  Document A    1     1    NA   NA  <NA>     <NA>## 2  First Page    1     2    NA   NA  <NA>     <NA>## 3 Second Page    2     2    NA   NA  <NA>     <NA>## 4  Document B    3     1    NA   NA  <NA>     <NA>## 5  First Page    3     2    NA   NA  <NA>     <NA>## 6 Second Page    4     2    NA   NA  <NA>     <NA>

Limitations bybackend

{xmpdf} featureexiftoolpdftkghostscript
Get XMP metadataYesNoNo
Set XMP metadataYesNoPoor: when documentation info metadata is set thenas a side effect it seems the documentation info metadata will also beset as XMP metadata
Get PDF bookmarksNoOkay: can only get Title, Page number, andLevelNo
Set PDF bookmarksNoOkay: can only set Title, Page number, andLevelGood: supports most bookmarks features includingcolor and font face but only action supported is to view a particularpage
Get PDF documentation infoGood: may “widen” datetimes which are less than“second” precisionYesNo
Set PDF documentation infoYesGood: may not handle entries with newlines inthemYes: as a side effect when documentation infometadata is set then it seems will also be set as XMP metadata
Concatenate PDF filesNoYesYes

Known limitations:

  • get_bookmarks_pdftk() doesn’t report information aboutbookmarks color, font face, and whether the bookmarks should start openor closed.
  • get_bookmarks_pdftools()’s doesn’t report informationabout bookmarks pages, color, font face, and whether the bookmarks
  • get_docinfo_exiftool() “widens” datetimes to secondprecision. An hour-only UTC offset will be “widened” to minuteprecision.
  • get_docinfo_pdftools()’s datetimes may not accuratelyreflect the embedded datetimes.
  • set_bookmarks_gs() supports most bookmarks featuresincluding color and font face but only action supported is to view aparticular page.
  • set_bookmarks_pdftk() only supports setting the title,page number, and level of bookmarks.
  • set_docinfo_pdftk() may not handle entries withnewlines in them.
  • All of theset_docinfo() methods currently do notsupport arbitrary info dictionary entries.
  • As a side effectset_docinfo_gs() seems to also updateany matching XPN metadata whileset_docinfo_exiftool() andset_docinfo_pdftk() don’t update any previously setmatching XPN metadata. Some pdf viewers will preferentially use thepreviously set document title from XPN metadata if it exists instead ofusing the title set in documentation info dictionary entry. Consideralso manually setting this XPN metadata usingset_xmp()
  • Old metadata information is usually not deleted from the files bythese operations (i.e. these operations are often theoreticallyreversible). If deleting the old metadata is important one may want toconsider callingqpdf::pdf_compress(input, linearize = TRUE) at theend.

External links

Metadata links

Related software

Note most of the R packages listed below are focused ongetting metadata rather thansettingmetadata and/or only provide low-level wrappers around the relevantcommand-line tools. Please feel free toopen apull request to add any missing relevant R packages.

exempi

exiftool

  • {exifr} providesa high-level wrapper to read metadata as well as a low-level wrapperaround theexiftool command-line tool. Can downloadexiftool.
  • {exiftoolr}provides high-level wrapper to read metadata as well as a low-levelwrapper around theexiftool command-line tool. Can downloadexiftool.
  • exiftool

exiv2

  • {exiv} read and write‘Exif’, ‘ID3v1’ and ‘ID3v2’ image/media tags
  • exiv2

other exif tools

  • {exif} reads EXIFfrom jpeg images
  • {magick} hasimage_attributes() which reads EXIF image tags.

ghostscript

  • {tools} hasfind_gs_cmd() to find aGhostScript executable in a cross-platform way.
  • ghostscript

poppler

qpdf

pdftk

tabula

xpdf

  • xpdf’spdfinfo tool

[8]ページ先頭

©2009-2025 Movatter.jp