Tx · LaTeX & TikZ

How to Add PDF Metadata in LaTeX

Published By the 9to5Science editorial team

At a glance

  1. 1. Load hyperref

    Add the hyperref package to your preamble, preferably after most other packages.

  2. 2. Set metadata fields

    Use hypersetup to provide the PDF title, author, subject, and keywords.

  3. 3. Keep values simple

    Use readable text rather than formatting commands in metadata fields.

  4. 4. Compile and inspect

    Rebuild the PDF and check its document properties in a PDF reader.

Advertisement

LaTeX can write descriptive information—such as a document’s title, author, subject, and keywords—into the PDF file. This information is called PDF metadata. It is separate from the text printed on the page, though PDF readers and other tools may display it or use it for indexing.

The usual method is to load hyperref and set its PDF fields with \hypersetup. The example below is a complete document you can compile and adapt.

Add metadata with hyperref

\documentclass{article}

\usepackage[T1]{fontenc}
\usepackage[unicode]{hyperref}

\hypersetup{
  pdftitle={A Short Guide to PDF Metadata},
  pdfauthor={Ada Lovelace},
  pdfsubject={A demonstration of PDF metadata in LaTeX},
  pdfkeywords={LaTeX, PDF, metadata},
  pdfcreator={LaTeX with hyperref}
}

\title{A Short Guide to PDF Metadata}
\author{Ada Lovelace}
\date{\today}

\begin{document}
\maketitle

This document has metadata that can be viewed in a PDF reader.

\end{document}

The hyperref package provides the metadata keys used here:

KeyWhat it describes
pdftitleThe document’s title
pdfauthorThe author or authors
pdfsubjectA short description of the document
pdfkeywordsSearch terms associated with the document
pdfcreatorThe application or system used to create the source document

Put \hypersetup{...} in the preamble, before \begin{document}. Loading hyperref after most other packages is a useful general convention, although some packages have specific ordering requirements. The unicode option asks hyperref to use Unicode for PDF strings where supported. If your metadata uses only basic English letters and punctuation, it is usually not essential.

Metadata is not the same as the title page

Commands such as \title{...} and \author{...} ordinarily provide information for the printed title page when you use \maketitle. They are not a reliable substitute for explicitly setting pdftitle and pdfauthor.

You can use the same text in both places, as in the example, or choose different values. For instance, the title page might show a long formal title while the PDF title field uses a shorter version that is easier to recognize in a file list. If you change the visible title or author later, update the metadata too so they do not disagree.

Compile and check the result

Compile the .tex file to create the PDF. Then open the PDF’s document properties in a reader—for example, look for File → Properties or an equivalent menu—and check the title, author, subject, and keywords. Menu names vary by application. You can also inspect the PDF with a command-line metadata utility if one is available.

The metadata is embedded in the PDF, not generated as a separate file. It may be visible to anyone who receives the PDF, and PDF software or search tools may use it. Do not put private information in these fields.

Common mistakes

  • Setting only \title and \author: These commands can affect the page but do not replace explicit PDF metadata settings. Set the pdf... keys when you want those fields populated.
  • Putting \hypersetup after \begin{document}: Set the document-wide values in the preamble so they are applied when the PDF is produced.
  • Using complicated TeX formatting in a field: Metadata is a PDF string, not typeset page content. Prefer plain text. Commands such as \textbf{...} or math expressions may fail, appear incorrectly, or trigger warnings.
  • Expecting the metadata to show on the page: These fields describe the PDF; they do not print a title, author, or keyword list. Use ordinary LaTeX text commands for visible content.
  • Assuming every tool displays every field: PDF readers differ in which properties they show. Inspect the generated file rather than relying only on the source code.

Unicode and richer metadata

For accented characters or non-Latin scripts, use an engine and font setup that supports the text you need, and check the resulting PDF in more than one viewer if the characters matter. The unicode option helps with PDF strings, but it cannot compensate for an engine or font that lacks the required characters.

hyperref covers common document-information fields. If a publisher or repository specifically requires metadata in XMP format, check its submission requirements: XMP is a separate metadata format, and setting the usual hyperref fields alone may not satisfy that requirement. The CTAN documentation for hyperref describes the package’s PDF options and metadata keys.

References

  1. The hyperref package documentation, CTAN

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.