[Tex/LaTex] Set PDF version with LuaTeX and pdfx

luatexpdfx

Consider the following example using the package pdfx version 1.5.8, setting the PDF version as suggested in https://tex.stackexchange.com/a/202301/99345 for LuaTeX 0.95:

\directlua{
if pdf.getminorversion() \string~= 7 then
  if (status.pdf_gone and status.pdf_gone > 0)
  or (status.pdf_ptr and status.pdf_ptr > 0) then
    tex.error("PDF version cannot be changed anymore")
  else
    pdf.setminorversion(7)
  end
end
}

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

\begin{document}
Content
\end{document}

When building the PDF output with LuaTeX version 1.0.4, the following error occurs:

! error:  (pdf backend): minorversion cannot be changed after data is written to the PDF file
!  ==> Fatal error occurred, no output PDF file produced!

Omitting the package pdfx produces a PDF document with the correct version number 1.7 set. How can the desired PDF version number be set in combination with LuaTeX and pdfx?

Best Answer

There was a bug in hyperref versions prior to v6.86a with the pdfa option, which set the PDF always to version 1.4. The latest version of hyperref (>6.86a) fixes that problem.