Obtaining a list of authors and keywords in the given document

I'm typesetting a document based on the Elsevier document class.

I want to use hyperref's \hypersetup to set title, author, and keywords of the generated PDF file to the corresponding values.

The problem is that I want \hypersetup values to be generated automatically; i.e. it takes the title of the paper and sets it as the title of the PDF file, and does the same for the author and keywords fields.

Here's what I came up with until now:

\documentclass{elsarticle}

\usepackage{hyperref}

\begin{document}

\title{A Test Title}

\author{John Doe}
\author{Jane Doe}
\author{John Smith}

\begin{abstract}
...
\end{abstract}

\begin{keyword}
key1, key2, key3, key4.
\end{keyword}

\maketitle

\makeatletter
\hypersetup{
pdfinfo={
Title={\@title},
Author={},
Keywords={}
}
}
\makeatother

\end{document}


As shown above, I used \@title (which is defined internally by elsarticle document class). I just don't know how to automatically include author names and keyword list (both of them in the comma-separated format).

-

Unfortunately elsarticle doesn't simply store the list of authors in a control sequence, nor the list of keywords, so you have to create your own:

\documentclass{elsarticle}

\usepackage{etoolbox,environ}
\makeatletter
\def\auto@authors{\@gobbletwo}
\let\kept@keyword\keyword
\let\kept@endkeyword\endkeyword

\let\keyword\relax\let\endkeyword\relax
\NewEnviron{keyword}{%
\expandafter\gdef\expandafter\auto@keywords\expandafter{\BODY}%
\kept@keyword\BODY\kept@endkeyword}
\makeatother

\usepackage{hyperref}

\begin{document}

\title{A Test Title}

\author{John Doe}
\author{Jane Doe}
\author{John Smith}

\begin{abstract}
...
\end{abstract}

\begin{keyword}
key1, key2, key3, key4.
\end{keyword}

\maketitle

\makeatletter
\hypersetup{
pdfinfo={
Title={\@title},
Author={\auto@authors},
Keywords={\auto@keywords}
}
}
\makeatother

\end{document}


Here's the (relevant) output of pdfinfo:

Title:          A Test Title
Subject:
Keywords:       key1, key2, key3, key4.
Author:         John Doe, Jane Doe, John Smith
Creator:        LaTeX with hyperref package

-