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}
- 3,862
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.
- 831
-
1That 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.86band 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.83mfrom 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 themanual.pdffor some reason. – Ilya Popov Sep 04 '18 at 20:33 -
1@IlyaPopov this is also the case of important other things such as
bookmarksdepthfor example. – Sep 04 '18 at 21:05 -
The hyperref manual for hyperref 2018/11/30 v6.88e does mention the
pdfusetitleoption (New Features, Option pdfusetitle). Also, using\title{\texorpdfstring{for \LaTeX\ output}{for PDF metadata}}and similar markup for\authorcan be wise if you have formatting instructions in your\titleor\author(althoughhyperrefseems to be smart about at least\\and babel-french's\bsccommand). – frougon May 22 '19 at 08:10 -
1As 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
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)
- 3,862
-
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 Jul 04 '16 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). – rallg Jan 30 '24 at 16:40
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.
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}
}}
- 131
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!)
- 14,890
-
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 Jul 24 '15 at 14:00
pdfproducerandpdfcreator? – lpdbw Aug 10 '12 at 09:59pdfusetitlehyperref option to automatically use\titleand\authoras said by @Chris. – Michael Nov 18 '19 at 08:47\usepackage[pdftex,pdfauthor={}]{hyperref}just so that to wipe out my name, right? – Matsmath Aug 31 '20 at 20:39pdftexis not necessary, as it can be autodetected. See https://ctan.math.illinois.edu/macros/latex/contrib/hyperref/doc/hyperref-doc.html#x1-80003.4 which discusses driver options. Some drivers can be autodetected, and some can't.pdftexis one of the ones that can. – Ken Bloom May 24 '21 at 15:55