可在 latex 中填写的 pdf

可在 latex 中填写的 pdf

我有如下代码,我想将其制作成可填写的pdf。可填充。价格和数量会自动给出总价和总金额。提前谢谢大家。

\documentclass[a4paper,8pt]{article}
\usepackage[legalpaper,left=4pt,right=14pt,top=13pt,bottom=14pt]{geometry}
\usepackage{hyperref}
\usepackage{multirow}
\usepackage{setspace} 

\begin{document}
    %set font type
    \fontfamily{lmss}\selectfont
    \singlespacing
    
    %begin form environment
    \begin{Form}[action=mailto:[email protected]?subject={The submitted form},method=post]
        
        
        \begin{flushleft}
            %\noindent\TextField[name=compay,width=5cm]{}\\[0mm]
            \LARGE{Company \\ Name \begin{flushright} \LARGE{Invoice}   \end{flushright} }
        \end{flushleft}
    
    
        \begin{flushright}
            \TextField[name=Date,width=5cm]{Date: } \\[0mm]
            \TextField[name=Invoce_No,width=5cm]{Invoce No: } \\[0mm]
        \end{flushright}
        
        \begin{table}[h]
            \centering
            \caption{My caption}
            \label{my-label}
            \begin{tabular}{lllll}
                Test Table & \multicolumn{2}{l}{} \\
                a   &   a  &  f  \\
                 \TextField[name=file_no,width=5cm]{Price: }   & \TextField[name=file_no,width=5cm]{Quantity: }    &    \TextField[name=file_no,width=5cm]{Total: }  \\
            
             \TextField[name=file_no,width=5cm]{Price: }   & \TextField[name=file_no,width=5cm]{Quantity: }    &    \TextField[name=file_no,width=5cm]{Total: }  \\
             
              &   &   \TextField[name=file_no,width=5cm]{Total Sum: }  \\
            \end{tabular}

        \end{table}
        
    \end{Form}
    
\end{document}

答案1

您必须为文本框指定唯一的名称。然后您可以使用 javascript,例如:

\documentclass[a4paper,8pt]{article}
\usepackage[legalpaper,left=4pt,right=14pt,top=13pt,bottom=14pt]{geometry}
\usepackage{hyperref}
\usepackage{multirow}
\usepackage{setspace}

\begin{document}
    %set font type
    \fontfamily{lmss}\selectfont
    \singlespacing

    %begin form environment
    \begin{Form}[action=mailto:[email protected]?subject={The submitted form},method=post]


        \begin{flushleft}
            %\noindent\TextField[name=compay,width=5cm]{}\\[0mm]
            \LARGE{Company \\ Name \begin{flushright} \LARGE{Invoice}   \end{flushright} }
        \end{flushleft}


        \begin{flushright}
            \TextField[name=Date,width=5cm]{Date: } \\[0mm]
            \TextField[name=Invoce_No,width=5cm]{Invoce No: } \\[0mm]
        \end{flushright}

        \begin{table}[h]
            \centering
            \caption{My caption}
            \label{my-label}
            \begin{tabular}{lllll}
                Test Table & \multicolumn{2}{l}{} \\
                a   &   a  &  f  \\
                 \TextField[name=price1,width=5cm]{Price: }   & \TextField[name=qty1,width=5cm]{Quantity: }    &    \TextField[name=total1,width=5cm,
                  calculate={%
                  var f_price = this.getField("price1");
                  var f_qty   = this.getField("qty1");
                  event.value = f_price.value * f_qty.value;}
                 ]{Total: }  \\

             \TextField[name=price2,width=5cm]{Price: }   & \TextField[name=qty2,width=5cm]{Quantity: }    &    \TextField[name=total2,width=5cm,
               calculate={%
                  var f_price = this.getField("price2");
                  var f_qty   = this.getField("qty2");
                  event.value = f_price.value * f_qty.value;}
                 ]{Total: }  \\

              &   &   \TextField[name=totalsum,width=5cm,
               calculate={%
                  var f_total1 = this.getField("total1");
                  var f_total2   = this.getField("total2");
                  event.value = f_total1.value +  f_total2.value;}
                 ]{Total Sum: }  \\
            \end{tabular}

        \end{table}

    \end{Form}

\end{document}

在此处输入图片描述

相关内容