[Tex/LaTex] Incompatibilities of cmap with fontenc/hyperref

copy/pastefont-encodingshyperrefincompatibilitypdftex

The following code doesn't compile (with pdflatex)

\documentclass{article}
\usepackage{cmap}
\usepackage[T1]{fontenc}
\usepackage[pdfa=true]{hyperref}

\begin{document}

Hello.

\end{document}

unless I omit either the fontenc-line or the pdfa=true-option from the hyperref-line. The error message I get says: ! pdfTeX error (setup): \pdfminorversion cannot be changed after data is written to the PDF file. Is there something I can do or is this an incompatibility?

Best Answer

The fatal error you get is

! pdfTeX error (setup): \pdfminorversion cannot be changed after data is writte
n to the PDF file.
<to be read again> 
                   \edef 
l.6 \begin{document}

Using \tracingall, this can be tracked down a bit more to the \AtBeginDocument hook. What it looks like is that hyperref wants to set some PDF settings at the start of the document when given the pdfa=true option. Normally, nothing will have been written to the PDF at that stage, so all is fine, but cmap has already written to the PDF so breaks this. The solution is to load cmap after hyperref.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[pdfa=true]{hyperref}
\usepackage{cmap}
\begin{document}

Hello.

\end{document}