22

Is it possible to create custom metadata key/values for a PDF file?

I can see (from other questions here) how to add title, author, keywords etc. However, I'm creating transcriptions of historical documents and I'd like to add some additional metadata, such as the record office holding the document and the document accession number.

The idea is that (in the future) when I want to make them available on the web I can write an app that can read the PDF to extract the metadata (via something like PDFBox or iText) to include it in a HTTP POST.

1

3 Answers 3

21

Package hyperref

Package hyperref supports the setting of arbitrary keys in the PDF information dictionary (see manual):

\documentclass{article}
\usepackage{hyperref}

\hypersetup{
  pdfinfo={
    RecordOffice={my office},
    AccessionNumber={42},
  }
}

\begin{document}
Hello World.
\end{document}

However, these keys are not standardized, thus most tools will not show them. But you can extract them via a PDF library.

Package hyperxmp

The PDF format also supports XMP (eXtensible Metadata Platform). More keywords are standardized there. See package hyperxmp of Scott Pakin.

2
  • That's great. I can add the metadata and query via Apache PDFBox.
    – MikeJ
    Feb 18, 2014 at 16:50
  • 1
    For the people that wanna check if a property was added and the command has worked well, just try this on terminal exiftool -S -DucumentVersion myDocument.pdf. This is for checking the property called "DucumentVersion". You should change it by the property that you just added. If the property appears, your property was added successfully Dec 4, 2022 at 22:31
9

There is also pdfx package. Here you have to add metadata as a separate .xmp file.

\documentclass{article}

\usepackage{lipsum}
\usepackage[a-1b]{pdfx}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.xmpdata}
\Keywords{pdfTeX\sep PDF/X-1a\sep PDF/A-b} 
\Title{Sample LaTeX input file} 
\Author{LaTeX project team} 
\Org{TeX Users Group}
\Doi{123456789} 
\end{filecontents*}
\begin{document}
\lipsum

\end{document}
0

All of the aforementioned methods work inside latex environment. In case you want to change some of the metadata information after the pdf is generated then take a look at my post-processing method.

This method uses only a text editor.

2
  • I do not think this is a valid answer, as a post-processing breaks the latex-workflow Dec 7, 2017 at 13:04
  • As I mentioned, It is an alternative. Especially when the source tex file is not accessible.
    – NKN
    Dec 7, 2017 at 15:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .