Typevia
Format Conversion

Introduction to PDF Metadata

When you create a document in LaTeX, the focus is usually on how the text looks on the printed or digital page. However, there is a hidden layer of information attached to every PDF file called metadata.

Metadata is "data about data." In the context of a PDF, this includes information like the document's title, the author's name, the subject, and keywords for search engines. This information doesn't appear on the actual pages of your document; instead, it appears in the "Document Properties" window of PDF viewers (like Adobe Acrobat or Preview) and is used by search engines to index your file.

Properly configured metadata is essential for:

  • Professionalism: Ensuring the file properties match the document content.
  • Search Engine Optimization (SEO): Helping others find your research or reports online.
  • Accessibility: Assisting screen readers in identifying the document correctly.

The Powerhouse: The hyperref Package

In the LaTeX ecosystem, the standard way to manage PDF metadata is through the hyperref package. While hyperref is most famous for creating clickable links and bookmarks, it also serves as the primary interface for embedding metadata into the PDF header.

Basic Setup

To begin, you must include the hyperref package in your preamble. It is a best practice to load hyperref as one of the last packages in your preamble, as it often redefines commands from other packages.

\documentclass{article}

% Other packages...

\usepackage{hyperref}

\begin{document}
Hello, World!
\end{document}

By default, hyperref will create a PDF, but the metadata will be empty or filled with default values. To customize it, we use the \hypersetup command.


Configuring Metadata with \hypersetup

The \hypersetup command allows you to define a list of "key=value" pairs. This is much cleaner than passing every option directly to the \usepackage command.

Standard Metadata Fields

The most commonly used keys for metadata are:

  • pdftitle: The title of the document.
  • pdfauthor: The name of the author(s).
  • pdfsubject: A brief description or abstract of the content.
  • pdfkeywords: A comma-separated list of keywords.
  • pdfcreator: The software used to create the document (usually LaTeX).

Practical Example

Here is how you would set up a standard academic paper:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{hyperref}

\hypersetup{
    pdftitle={Impact of LaTeX on Document Automation},
    pdfauthor={Jane Doe},
    pdfsubject={LaTeX Documentation},
    pdfkeywords={LaTeX, PDF, Metadata, Typesetting},
    pdfproducer={XeLaTeX},
    pdfcreator={LaTeX with hyperref}
}

\begin{document}
\title{Impact of LaTeX on Document Automation}
\author{Jane Doe}
\maketitle

This document contains embedded metadata that you can view in your PDF reader's properties.
\end{document}

Note: Even if you use \title{...} and \author{...} to generate a visible title page, you still need to define pdftitle and pdfauthor inside \hypersetup if you want them to appear in the file's properties.


Controlling the PDF Viewer Behavior

Beyond text-based metadata, you can also control how the PDF viewer (like Adobe Reader) behaves when the file is first opened. This is done using the same \hypersetup command.

Useful Viewer Options:

  • pdfstartview={FitH}: Opens the PDF fitting the width of the page to the window.
  • pdfpagemode=UseOutlines: Opens the PDF with the bookmarks (table of contents) sidebar already visible.
  • pdfdisplaydoctitle=true: Tells the PDF viewer to display the pdftitle in the window's title bar instead of the file name (e.g., "My Thesis" instead of thesis_final_v2.pdf).

Example with Viewer Preferences:

\hypersetup{
    pdftitle={Annual Financial Report 2023},
    pdfauthor={Acme Corp},
    pdfdisplaydoctitle=true,     % Show title instead of filename
    pdfpagemode=UseOutlines,     % Show bookmarks on open
    pdfstartview={FitV},         % Fit the page vertically
    colorlinks=true,             % Optional: make links colorful instead of boxed
    linkcolor=blue,
    urlcolor=cyan
}

Handling Special Characters: \texorpdfstring

One common pitfall for beginners is using LaTeX commands (like math mode or manual line breaks) inside metadata fields. Since PDF metadata is stored as plain text or simple Unicode, it cannot render complex LaTeX formatting.

If you try to put a math formula in your title, you might get a warning or garbled text in the PDF properties: pdftitle={Analysis of $E=mc^2$} $\rightarrow$ Potential Error

To solve this, use the \texorpdfstring{LaTeX code}{Plain text} command. It tells LaTeX: "Use the first part for the document layout, but use the second part for the PDF metadata."

Example with Special Characters:

\hypersetup{
    pdftitle={\texorpdfstring{The Role of \alpha{} in Physics}{The Role of Alpha in Physics}},
    pdfauthor={Researcher Name}
}

Best Practice: For maximum compatibility, always use the unicode=true option in hyperref (or \hypersetup). This ensures that accented characters and non-Latin scripts are encoded correctly in the PDF properties.


Advanced: XMP Metadata with hyperxmp

While hyperref handles basic PDF metadata well, modern standards (like PDF/A for long-term archiving) often require metadata in a format called XMP (Extensible Metadata Platform).

If you need to include more detailed information, such as copyright status, licensing (like Creative Commons), or contact information, you should use the hyperxmp package alongside hyperref.

\usepackage{hyperref}
\usepackage{hyperxmp}

\hypersetup{
    pdftitle={Open Source Guide},
    pdfauthor={John Smith},
    pdfcopyright={Copyright (c) 2023 by John Smith. Licensed under CC BY 4.0},
    pdflicenseurl={http://creativecommons.org/licenses/by/4.0/}
}

Common Mistakes and Tips

1. Forgetting to Recompile

Changes to metadata often require two or three "runs" of your LaTeX compiler (pdflatex, xelatex, or lualatex) to ensure the internal references are updated correctly.

2. Forbidden Characters

Avoid using %, \, or _ inside \hypersetup values without careful escaping. If a character has a special meaning in LaTeX, it might break the metadata generation.

3. Verification

How do you know if it worked?

  • In Adobe Acrobat: File > Properties > Description.
  • In Chrome/Edge: Open the PDF, click the three dots > Document properties.
  • In Linux (Terminal): Use the command pdfinfo yourfile.pdf.

4. Privacy Tip

Metadata can sometimes contain sensitive information (like your operating system or file paths). If you are submitting a paper for "Double-Blind Review," ensure you remove the pdfauthor field from your \hypersetup before submitting!

Summary Checklist

  • Load hyperref at the end of your preamble.
  • Use \hypersetup to organize your metadata keys.
  • Set pdftitle and pdfauthor at a minimum.
  • Use \texorpdfstring if your title contains math or symbols.
  • Set pdfdisplaydoctitle=true for a more professional look in the viewer.