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!
6 Answers
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} - 17What's the difference between
pdfproducerandpdfcreator?lpdbw– lpdbw2012-08-10 09:59:56 +00:00Commented Aug 10, 2012 at 9:59 - 2Isn't pdfproducer and pdfcreator set automatically? At least this seems to be the case for me...Martin Thoma– Martin Thoma2015-06-14 10:50:51 +00:00Commented Jun 14, 2015 at 10:50
- 2Do you really need the switch 'pdftex' to make it work? I tried without and writing metadata worked.lcnittl– lcnittl2016-04-02 08:25:46 +00:00Commented Apr 2, 2016 at 8:25
- 6All of these options (and more) are documented (with their default values) in the hyperref manual, section 3.9 Big alphabetical list.Lekensteyn– Lekensteyn2016-05-28 22:29:34 +00:00Commented May 28, 2016 at 22:29
- 3
pdftexis not necessary, as it can be autodetected. See ctan.math.illinois.edu/macros/latex/contrib/hyperref/doc/… which discusses driver options. Some drivers can be autodetected, and some can't.pdftexis one of the ones that can.Ken Bloom– Ken Bloom2021-05-24 15:55:05 +00:00Commented May 24, 2021 at 15:55
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.
- 1That is a nice option, but if you're using several \author tags it only seems to include the last one.Anyon– Anyon2018-04-24 19:35:51 +00:00Commented Apr 24, 2018 at 19:35
- Which version of hyperref has this option? Version from Jan 2017 does not seem to.Ilya Popov– Ilya Popov2018-09-03 17:15:58 +00:00Commented Sep 3, 2018 at 17:15
- 2@jfbu Oh, I see now. So, it is documented in
README, but not in themanual.pdffor some reason.Ilya Popov– Ilya Popov2018-09-04 20:33:37 +00:00Commented Sep 4, 2018 at 20:33 - 1@IlyaPopov this is also the case of important other things such as
bookmarksdepthfor example.user4686– user46862018-09-04 21:05:50 +00:00Commented Sep 4, 2018 at 21:05 - 3As 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. github.com/latex3/hyperref/issues/169hmijail– hmijail2024-01-23 07:20:07 +00:00Commented Jan 23, 2024 at 7:20
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)
- 8In 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– Dimitri Podborski2016-07-04 14:32:47 +00:00Commented Jul 4, 2016 at 14:32
- Unless all of the metadata is Latin-1, there may be problems if you use
\pdfinfodirectly. This is because the data must be encoded in a certain way, which is not what you would expect for other languages. Packagehyperrefdoes the necessary encoding. Similarly for XMP, which must be encoded utf-8 with a few characters escaped (because they are active characters in PDF).user287367– user2873672024-01-30 16:40:18 +00:00Commented Jan 30, 2024 at 16:40
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} }} 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.
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!)
- 1For this you can even use the
hyperrefpackage as stated above in a blank document where you just import your desired PDF using thepdfpagespackage.Andrestand– Andrestand2015-07-24 14:00:19 +00:00Commented Jul 24, 2015 at 14:00