174

I am writing a document using LaTeX and generating PDF. Can anybody tell me how I can generate the PDF metadata, e.g. author or title, from LaTeX? On Windows XP, I am using MikTex's texify to generate the PDF. On linux, I am using pdflatex to generate the PDF. Any answers for either platform would be much appreciated!

doncherry
  • 54,637
kc2001
  • 2,601

6 Answers6

208

Use the hyperref package, included in pretty much every latex distribution these days.

\usepackage[pdftex,
            pdfauthor={Your Name},
            pdftitle={The Title},
            pdfsubject={The Subject},
            pdfkeywords={Some Keywords},
            pdfproducer={Latex with hyperref, or other system},
            pdfcreator={pdflatex, or other tool}]{hyperref}
Ken Bloom
  • 3,862
67

As others have already answered, I like to use hyperref. However, as my documents often have \author and \title commands I do not want to repeat myself in the package parameters. Luckily, hyperref also has a parameter for that. If you want it to read the information from your \author and similar tags, simply include it like this:

\usepackage[pdfusetitle]{hyperref}

Note: As commented by @hmijail, this option might be gone in future versions of the hyperref package. See also a GitHub comment of one of the package maintainters.

Chris
  • 831
  • 1
    That is a nice option, but if you're using several \author tags it only seems to include the last one. – Anyon Apr 24 '18 at 19:35
  • Which version of hyperref has this option? Version from Jan 2017 does not seem to. – Ilya Popov Sep 03 '18 at 17:15
  • @IlyaPopov which version exactly do you use? It works for me with current version 2018/02/06 v6.86b and I doubt very much it does not work with "Jan 2017" version. –  Sep 04 '18 at 06:58
  • I tested with 2012/11/06 v6.83m from TeXLive 2015 and it works too. It seems very improbable it ceased working in-between that version and current one. –  Sep 04 '18 at 07:01
  • @jfbu Indeed it works, although is not documented in the hyperref manual. Thanks! – Ilya Popov Sep 04 '18 at 17:42
  • @IlyaPopov its is documented in the README: you need to click on the triangle next to "Hyperref manual" bookmark, then click on README. You find it in table of contents and on page 13 of file with title README for hyperref bundle. –  Sep 04 '18 at 18:53
  • 2
    @jfbu Oh, I see now. So, it is documented in README, but not in the manual.pdf for some reason. – Ilya Popov Sep 04 '18 at 20:33
  • 1
    @IlyaPopov this is also the case of important other things such as bookmarksdepth for example. –  Sep 04 '18 at 21:05
  • The hyperref manual for hyperref 2018/11/30 v6.88e does mention the pdfusetitle option (New Features, Option pdfusetitle). Also, using \title{\texorpdfstring{for \LaTeX\ output}{for PDF metadata}} and similar markup for \author can be wise if you have formatting instructions in your \title or \author (although hyperref seems to be smart about at least \\ and babel-french's \bsc command). – frougon May 22 '19 at 08:10
  • 1
    As of 2024, there are multiple issues in the hyperref repo pointing to pdfusetitle being problematic and being on its way out. Probably best to use other options. https://github.com/latex3/hyperref/issues/169 – hmijail Jan 23 '24 at 07:20
48

Use the \pdfinfo macro, where the contents are given in PDF notation:

\pdfinfo{
   /Author (Nicola Talbot)
   /Title  (Creating a PDF document using PDFLaTeX)
   /CreationDate (D:20040502195600)
   /Subject (PDFLaTeX)
   /Keywords (PDF;LaTeX)
}

(Source: http://theoval.cmp.uea.ac.uk/~nlct/latex/pdfdoc/pdfdoc/pdfdoc.html)

Ken Bloom
  • 3,862
  • 8
    In combination with hyperref package it might cause some problems like described here. Just wanted to mention this, since I just experienced the same problem. – Dimitri Podborski Jul 04 '16 at 14:32
  • Unless all of the metadata is Latin-1, there may be problems if you use \pdfinfo directly. This is because the data must be encoded in a certain way, which is not what you would expect for other languages. Package hyperref does the necessary encoding. Similarly for XMP, which must be encoded utf-8 with a few characters escaped (because they are active characters in PDF). – rallg Jan 30 '24 at 16:40
5

You can use xmpincl, "which allows you to add arbitrary metadata in the Adobe XMP (Extensible Metadata Platform) format. But you have to write a separate XML file to do this" (suggested in threads here). They also propose a more recent package hyperxmp.

You can find an example .xmpdata file and other files needed on creating high-quality PDF/A documents using LaTeX.

This instruction not only provides files that work better than TeXLive standard packages for inclusion of metadata (they fixed some bugs), but also shows how to create PDF/A which has very good properties optimized for long-term archiving.

3

For some reason none of the solutions here worked for me. I tried with this and it worked:

\AfterPreamble{\hypersetup{
  pdfauthor={John Doe},
  pdftitle={The Title},
  pdfsubject={The Subject}
}}
metters
  • 131
1

You explicitly asked for generating the metadata from LaTeX, and using one of the answers of Ken Bloom seems the right way for me.

For the case that you want to add metadata to a file not created with LaTex (or an existing pdf you do not want to recompile) I just wanted to point you to http://www.bureausoft.com/products.html#PDF%20Info%20%28Freeware%29 which is a free Windows programme to change the pdf metadata. (I do not recommend this instead of the pdfLaTeX way!)

Stephen
  • 14,890
  • 1
    For this you can even use the hyperref package as stated above in a blank document where you just import your desired PDF using the pdfpages package. – Andrestand Jul 24 '15 at 14:00