[Tex/LaTex] Problem between hyperref, pdfx and kvsetkeys

errorshyperrefpdf-a

I have this minimal example:

\documentclass{article}
\usepackage{hyperref}
\usepackage[a-1b]{pdfx}

\begin{document}
Foo Bar
\end{document}

which results in an error when compiled with either pdflatex or lualatex:

(c:/Local/TeXLive/texmf-dist/tex/latex/pdfx/l8uenc.def)

! Package kvsetkeys Error: Undefined key `pdftex,pdfa,pdfversion=1.4'.

See the kvsetkeys package documentation for explanation.
Type  H <return>  for immediate help.
 ...

l.806  }

The problem is with line 794 in pdfx.sty (when compiling with luatex):

\hypersetup{\pdfx@pdfAE@opts@luatex}%

The arguments are defined at line 750 in pdfx.sty:

\def\pdfx@pdfAE@opts@luatex{pdftex,pdfa,pdfversion=1.\thepdfminorversion}%

but it seems that \hypersetup is not able to parse them.
The pdfx.sty file states that:

[2016/05/03 v1.5.8 PDF/X and PDF/A support (CVR/HTH/RRM/PS)]

The other files are from TeXLive 2016.

Is there a simple fix for this situation?
Thanks in advance.

Best Answer

Let pdfx load hyperref:

\documentclass{article}
\usepackage[a-1b]{pdfx}

\begin{document}
Foo Bar
\end{document}

Generally, hyperref should be loaded late - last excepting packages which specifically require it be loaded first.