使用 LaTeX 制作包含表单的 PDF 文档容易吗?我尝试使用 TextFields,但我的一个朋友说它不适用于每个操作系统的 PDF 阅读器?
答案1
将来请注意所有问题都应包括 MWE。如果你提供帮助,你很可能会得到更多有用的帮助,同时也会增加愿意提供帮助的人数。
在本例中,我提供了一个简单的表单示例,该表单包含多行文本字段和选择菜单。前者中的一些具有默认文本,而其他一些则没有。后者使用下拉框,允许用户为每个项目选择三种可能性之一。每组项目都设置了统一的默认值。
请注意,表单在所有 PDF 查看器中看起来并不完全相同,并且某些 PDF 查看器根本不支持表单字段。
还要注意的是,Adobe Reader 不允许用户保存已填写的表格。不过,许多其他查看器(例如 Okular)可以做到这一点。
首次尝试
\documentclass{article}
\usepackage{hyperref}
\begin{document}
\pagestyle{empty}
\begin{Form}
\centering
\TextField[charsize={10pt},multiline=true,height={60mm},width={100mm},name={textfield1},bordercolor={1 1 1}]{First, a simple text field with no default text:\\
}
\vskip 5pt
\begin{minipage}[b]{.35\textwidth}
Usage of \verb|\ChoiceMenu|:
\begin{itemize}
\item aspect 1 \hspace*{\fill}\ChoiceMenu[name=aspect1,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{positive=p,negative=g,neither=n}
\item aspect 2 \hspace*{\fill}\ChoiceMenu[name=aspect2,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{positive=p,negative=g,neither=n}
\item aspect 3 \hspace*{\fill}\ChoiceMenu[name=aspect3,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{positive=p,negative=g,neither=n}
\item aspect 4 \hspace*{\fill}\ChoiceMenu[name=aspect4,combo=true,,menulength=1,bordercolor={0.2 0.2 0.7}]{}{positive=p,negative=g,neither=n}
\item aspect 5 \hspace*{\fill}\ChoiceMenu[name=aspect5,combo=true,,menulength=1,bordercolor={0.2 0.2 0.7}]{}{positive=p,negative=g,neither=n}
\item aspect 6 \hspace*{\fill}\ChoiceMenu[name=aspect6,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{positive=p,negative=g,neither=n}
\item aspect 7 \hspace*{\fill}\ChoiceMenu[name=aspect7,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{positive=p,negative=g,neither=n}
\end{itemize}
\TextField[charsize={10pt},multiline=true,height={10mm},width={.9\linewidth},name={moreaspects},bordercolor={0.2 0.2 0.7},default={additional aspects}]{\mbox{}
}
\end{minipage}
\hfill
\begin{minipage}[b]{.55\textwidth}
Note that \verb|name|s must be unique:
\begin{itemize}
\item possession of feature 1 \hspace*{\fill}\ChoiceMenu[name=feature1,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{possesses=p,lacks=l,uncertain=u}
\item possession of feature 2 \hspace*{\fill}\ChoiceMenu[name=feature2,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{possesses=p,lacks=l,uncertain=u}
\item possession of feature 3 \hspace*{\fill}\ChoiceMenu[name=feature3,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{possesses=p,lacks=l,uncertain=u}
\item possession of feature 4 \hspace*{\fill}\ChoiceMenu[name=feature4,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{possesses=p,lacks=l,uncertain=u}
\item possession of feature 5 \hspace*{\fill}\ChoiceMenu[name=feature5,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{possesses=p,lacks=l,uncertain=u}
\item possession of feature 6 \hspace*{\fill}\ChoiceMenu[name=feature6,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{possesses=p,lacks=l,uncertain=u}
\item possession of feature 7 \hspace*{\fill}\ChoiceMenu[name=feature7,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{possesses=p,lacks=l,uncertain=u}
\end{itemize}
\TextField[charsize={10pt},multiline=true,height={10mm},width={.9\linewidth},name={morefeats},bordercolor={0.2 0.2 0.7},default={possession of additional features}]{\mbox{}
}
\end{minipage}
\end{Form}
\end{document}
以下是在 Okular 中填写的表单,其中显示了表单字段:
修正代码
上面的内容非常好,只是当表单字段未激活时(或者,显然,当您将内容复制为要png
在此处发布的内容时),我们的选择菜单不会显示列表中的第一个(默认)项目。因此,最好将第一个项目设置为空白/中性设置,将三种可能性中的第一个设置为菜单中的第二个项目:
\documentclass{article}
\usepackage{hyperref}
\begin{document}
\pagestyle{empty}
\begin{Form}
\centering
\TextField[charsize={10pt},multiline=true,height={60mm},width={100mm},name={textfield1},bordercolor={1 1 1}]{First, a simple text field with no default text:\\
}
\vskip 5pt
\begin{minipage}[b]{.35\textwidth}
Usage of \verb|\ChoiceMenu|:
\begin{itemize}
\item aspect 1 \hspace*{\fill}\ChoiceMenu[name=aspect1,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{selection=none,positive=p,negative=g,neither=n}
\item aspect 2 \hspace*{\fill}\ChoiceMenu[name=aspect2,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{selection=none,positive=p,negative=g,neither=n}
\item aspect 3 \hspace*{\fill}\ChoiceMenu[name=aspect3,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{selection=none,positive=p,negative=g,neither=n}
\item aspect 4 \hspace*{\fill}\ChoiceMenu[name=aspect4,combo=true,,menulength=1,bordercolor={0.2 0.2 0.7}]{}{selection=none,positive=p,negative=g,neither=n}
\item aspect 5 \hspace*{\fill}\ChoiceMenu[name=aspect5,combo=true,,menulength=1,bordercolor={0.2 0.2 0.7}]{}{selection=none,positive=p,negative=g,neither=n}
\item aspect 6 \hspace*{\fill}\ChoiceMenu[name=aspect6,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{selection=none,positive=p,negative=g,neither=n}
\item aspect 7 \hspace*{\fill}\ChoiceMenu[name=aspect7,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{selection=none,positive=p,negative=g,neither=n}
\end{itemize}
\TextField[charsize={10pt},multiline=true,height={10mm},width={.9\linewidth},name={moreaspects},bordercolor={0.2 0.2 0.7},default={additional aspects}]{\mbox{}
}
\end{minipage}
\hfill
\begin{minipage}[b]{.55\textwidth}
Note that \verb|name|s must be unique:
\begin{itemize}
\item possession of feature 1 \hspace*{\fill}\ChoiceMenu[name=feature1,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{selection=none,possesses=p,lacks=l,uncertain=u}
\item possession of feature 2 \hspace*{\fill}\ChoiceMenu[name=feature2,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{selection=none,possesses=p,lacks=l,uncertain=u}
\item possession of feature 3 \hspace*{\fill}\ChoiceMenu[name=feature3,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{selection=none,possesses=p,lacks=l,uncertain=u}
\item possession of feature 4 \hspace*{\fill}\ChoiceMenu[name=feature4,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{selection=none,possesses=p,lacks=l,uncertain=u}
\item possession of feature 5 \hspace*{\fill}\ChoiceMenu[name=feature5,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{selection=none,possesses=p,lacks=l,uncertain=u}
\item possession of feature 6 \hspace*{\fill}\ChoiceMenu[name=feature6,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{selection=none,possesses=p,lacks=l,uncertain=u}
\item possession of feature 7 \hspace*{\fill}\ChoiceMenu[name=feature7,combo=true,menulength=1,bordercolor={0.2 0.2 0.7}]{}{selection=none,possesses=p,lacks=l,uncertain=u}
\end{itemize}
\TextField[charsize={10pt},multiline=true,height={10mm},width={.9\linewidth},name={morefeats},bordercolor={0.2 0.2 0.7},default={possession of additional features}]{\mbox{}
}
\end{minipage}
\end{Form}
\end{document}