How to create unique textfields in a pdf form without specifying textfield names

This question is related to Generating unique names in textfield

I cannot use the solution given in the above question because I use hyperref for generating my pdf form.

In my document I have many tables and I would like to create a pdf form in them. The name of textfields are unimportant, the user should be just able to fill them.

The problem is that when the user tries to fill one of the textfields in a pdf viewe, other fields are filled too.

If I use \TextField{} instead of \TextField{\ }, the textfields do not appear when I open the pdf file in Acrobat reader.

\documentclass{article}
\usepackage{hyperref}

\begin{document}

\begin{Form}
\begin{tabular}{llll}
A &  B  & C &  D  \\
\TextField{\ }  & \TextField{\ } & \TextField{\ } & \TextField{\ }\\
\TextField{\ }  & \TextField{\ } & \TextField{\ } & \TextField{\ } \\
\TextField{\ }  & \TextField{\ } & \TextField{\ } & \TextField{\ }
\end{tabular}
\end{Form}

\end{document}


text fields needs an unique name, but you can generate it e.g. with a counter and a new command:

\documentclass{article}
\usepackage{hyperref}
\newcounter{textfield}
\newcommand\AutoTextField{\stepcounter{textfield}\TextField[width=2cm,name=autotextfield\thetextfield]{}}
\begin{document}

\begin{Form}
\begin{tabular}{llll}
A &  B  & C &  D  \\
\AutoTextField  & \AutoTextField & \AutoTextField & \AutoTextField\\
\AutoTextField  & \AutoTextField & \AutoTextField & \AutoTextField \\
\AutoTextField  & \AutoTextField & \AutoTextField & \AutoTextField
\end{tabular}
\end{Form}

\end{document}


• Thank you, your solution works. May I ask why you have put autotextfield in name=autotextfield\thetextfield? It seems that your code also works without it.
– Name
Sep 14, 2020 at 15:19
• no without it, it doesn't work, the field then don't unique names. Sep 14, 2020 at 16:00