How can I programmatically populate a PDF's pdfcreator field?
pdfTeX
The TeX compiler pdfTeX already sets some keys as default:
/Producer (pdfTeX-1.40.15)
/Creator (TeX)
/CreationDate (D:20140506215840+02'00')
/ModDate (D:20140506215840+02'00')
/Trapped /False
/PTEX.Fullbanner (This is pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2014) kpathsea version 6.2.0)
Some of these entries can be overwritten via \pdfinfo
or via \hypersetup
if hyperref
is loaded. A nice feature of pdfTeX is, that if it detects the setting of standard keys in \pdfinfo
, then pdfTeX suppresses its setting to
avoid duplicate keys in the same dictionary with different values. Therefore it
is possible for the user or hyperref
to override the setting of pdfTeX.
The default of hyperref
's values are (line breaks added for better readability):
/Author()
/Title()
/Subject()
/Creator(LaTeX with hyperref package)
/Producer(pdfTeX-1.40.15)
/Keywords()
Also the other entries can be set by hyperref
(pdfcreationdate
, pdfmoddate
, ...)
Version number of pdfTeX
Since the version number scheme of pdfTeX has changed in the past, the algorithm for the versions specification is quite complex, from hpdftex.def
:
\def\@pdfproducer{pdfTeX}%
\ifx\eTeXversion\@undefined
\else
\ifx\eTeXversion\relax
\else
\ifnum\eTeXversion>0 %
\def\@pdfproducer{pdfeTeX}%
\fi
\fi
\fi
\ifx\pdftexversion\@undefined
\else
\ifnum\pdftexversion<100 %
\edef\@pdfproducer{%
\@pdfproducer
\the\pdftexversion.\pdftexrevision
}%
\else
\ifnum\pdftexversion<130 %
\edef\@pdfproducer{%
\@pdfproducer-%
\expandafter\@car\the\pdftexversion\@empty\@nil.%
\expandafter\@cdr\the\pdftexversion\@empty\@nil
\pdftexrevision
}%
\else
\ifnum\pdftexversion<140 %
\else
\def\@pdfproducer{pdfTeX}%
\fi
\edef\@pdfproducer{%
\@pdfproducer-%
\expandafter\@car\the\pdftexversion\@empty\@nil.%
\expandafter\@cdr\the\pdftexversion\@empty\@nil.%
\pdftexrevision
}%
\fi
\fi
\fi
Other drivers
Package hyperref
also sets information entries with the other drives. But it can happen, that the driver insists of its setting for some of the keys (/Creator
, ...).
\pdftexbanner
(introduced in pdfTeX 1.20a; see the pdfTeX user manual) produces the output:
This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013/W32TeX) kpathsea version 6.1.1
and contains the version of pdfTeX being used to process the document. You can extract just the pdfTex version using the following:
\makeatletter
\def\extractpdftexversion#1-#2-#3 #4\@nil{#3}
\edef\pdftexversion{\expandafter\extractpdftexversion\pdftexbanner\@nil}
\makeatother
Here \extractpdftexversion
expects an argument text of the form <stuffA>-<stuffB>-<stuffC> <stuffD>\@nil
, and only returns <stuffC>
(that is, the text delimited on the left by -
and on the right by a space
). You can add it to your PDF document properties using
\pdfinfo{
/Producer (pdfTeX \pdftexversion)
}
\documentclass{article}
\makeatletter
\def\extractpdftexversion#1-#2-#3 #4\@nil{#3}
\edef\pdftexversion{\expandafter\extractpdftexversion\pdftexbanner\@nil}
\makeatother
\pdfinfo{
/Producer (pdfTeX \pdftexversion)
}
\begin{document}
\pdftexbanner
\end{document}
No explicit need to use hyperref
(see Is hyperref
really the best way to add metadata to a TeX file?).