Adding PDF metadata in LaTeX
- May 29, 2012 |
- 4 Comments
When working on a LaTeX project of some value, you might want to add your credentials to the PDF metadata. This way, readers of the document will know who made the document and what its about without actually opening the document. Adding metadata might also be a good idea for copyright reasons, etc. As always, there are multiple ways of adding the data to documents. In this post I’ll explain the way I do it (and it isn’t difficult at all!).
The pdfinfo command
We will be using the pdfinfo command for adding the metadata. This command comes with pdfTeX. Using it is daily easy; all the metadata is put inside the argument of this command. Let’s show this with an example:
\pdfinfo{ /Author (Author Name) /Title (Adding PDF metadata in LaTeX) /Keywords (PDF;LaTeX;howtoTeX.com) } |
In this example, an author tag, title tag and keywords are added to the PDF metadata when the LaTeX document is compiled. Note that the fields always start with a slash (/)
The metadata fields
The available fields to put inside the pdfinfo command are the following:
/Title: title of the document/Author: author of the document/Creator: PDF creator/Producer: PDF producer/CreationDate: creation date/ModDate: modification date/Subject: subject of the document/Keywords: keywords, separated by a semicolon (;)
One note about the time fields. These should be in the format D:YYYYMMDDHHmmss (so the actual date is preceded by D:). For example:
\pdfinfo{ /CreationDate (D:20120501205500) } |
This way, the creation date will be May 1, 2012 at 20:55:00h. This seems rather cumbersome, so let’s give an alternative using the datetime. This package introduces the \pdfdate command which also can be used: For example:
\usepackage{datetime} \pdfinfo{ /CreationDate (D:\pdfdate) } |
Possible errors
The pdfinfo command comes with pdfTeX or pdfLaTeX, meaning that it will not work when a document is compiled with something else that pdfTeX/pdfLaTeX. On this site a nice error check is found, by making use of the ifpdf package:
\usepackage{ifpdf} \ifpdf \pdfinfo{ /Author (Author Name) /Title (Adding PDF metadata in LaTeX) /Keywords (PDF;LaTeX;howtoTeX.com) } \fi |
In words, this piece of code only reads the pdfinfo command if the document is compiled to PDF format (with pdfTeX/pdfLaTeX).
Alternatives
An alternative way would be to use the hyperref package (which is one of the essential LaTeX package I posted about). The necessary commands are described in section 3.6 of its documentation.
Will this work with xelatex? how about lualatex? both these engines’ output is pdf.
If PDF is the output I don’t see why it would work. But someone might want to verify this for me.
Is there a difference between this and using hyperref to add PDF meta-data?
No there is not, as far as I know. I just prefer the method described in this post (but note that I pointed out the
hyperrefpackage).