4

I have nested latex classes. A base class sets company-wide styles and contains this:

\ProvidesClass{companydoc}
\LoadClass{report}
\RequirePackage{hyperref}

\hypersetup{
    colorlinks=true,
    linkcolor=blue,
    filecolor=magenta,
    urlcolor=cyan,
    bookmarks=true,
}

The next class is for reports that need approval. It needs to add a few custom meta-data fields:

\ProvidesClass{approvaldoc}
\LoadClass{companydoc}

\necommand{\SetApprovalData}[2]{
  \hypersetup{
    pdfinfo={
      ApprovingManager={#1},
      ApprovalDate={#2}
    }
  }
}

Will approvaldoc's \hypersetup override or augment companydoc's \hypersetup?

Assuming augmentation is possible, If I want to go even further, the next class is specifically for expense reports:

\ProvidesClass{expensereport}
\LoadClass{approvaldoc}

\newcommand{\SetExpenseTotal}[1]{
  \hypersetup{
    pdfinfo={
      ExpenseTotal={#1}
    }
  }
}

Here, I assume that we will override approvaldoc's pdfinfo. If so, can I get the current value of pdfinfo, so I can append data to it?

1 Answer 1

6

You can use it as often as you want. With classical hyperref the pdfinfo is set at the end of the first page. So if you run this document

\documentclass{article}
\usepackage{hyperref}
\hypersetup{pdfinfo={ABC=aaa}}
\hypersetup{pdfinfo={CDE=ccc}}
\hypersetup{pdfinfo={CDE=ddd}}
\begin{document}
aaa
\hypersetup{pdfinfo={FGH=fff}}

\newpage 

bbbb
\hypersetup{pdfinfo={XYZ=xxx}}
\end{document}

you will get these entries

/ABC(\376\377\000a\000a\000a)
/CDE(\376\377\000d\000d\000d)
/FGH(\376\377\000f\000f\000f)

So the second CDE wins, and the XYZ on the last page is lost.

If you use the new pdfmanagement by adding \DocumentMetadata at the begin, then the new hyperref driver will set the Info dictionary at the end of the document and the XYZ is used too.

\DocumentMetadata{} 
\documentclass{article}
\usepackage{hyperref}
\hypersetup{pdfinfo={ABC=aaa}}
\hypersetup{pdfinfo={CDE=ccc}}
\hypersetup{pdfinfo={CDE=ddd}}
\begin{document}
aaa
\hypersetup{pdfinfo={FGH=fff}}

\newpage 

bbbb
\hypersetup{pdfinfo={XYZ=xxx}}
\end{document}

gives

/ABC <FEFF006100610061>
/CDE <FEFF006400640064>
/FGH <FEFF006600660066>
/XYZ <FEFF007800780078>

Be aware that in PDF 2.0 the Info Dictionary is deprecated and such data should be set in the XMP metadata instead.

3
  • Your last sentence is interesting. I'm on Debian 11 and pdfinfo out.pdf gives PDF version: 1.5 and does not display the metadata. If I use pdftk out.pdf dump_data I see my metadata in InfoKey and InfoValue fields. Is this related to Info Dictionary vs XMP metadata? How can I get hypersetup to set the XMP metadata instead?
    – Stewart
    Commented Oct 18, 2022 at 8:35
  • you can use hyperxmp to add XMP metadata (that is an XML file embedded in the pdf), but it will not honor your local data in pdfinfo, you would have to use other keys, see the documentation. It is not really extensible, so if you want to add really your own XML data, you must use the new code in the pdfmanagement but this would require a really current TeX system, and you would have to discuss with me the interfaces ;-). I can't know if you really need that, perhaps pdf 1.5 and Info is fine for you. Commented Oct 18, 2022 at 8:45
  • hyperxmp looks significantly more complicated, especially with custom fields. I think pdf1.5 is fine. Thanks.
    – Stewart
    Commented Oct 18, 2022 at 8:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .