1

I have a code as follows and I would like to make it a fillable pdf. fillable. Where the price and quantity will give the total automatically and the Total Sum. Many thanks in advance.

\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:forms@stackexchange.invalid?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}

  • Maybe this answer to a similar question will help you get started: https://tex.stackexchange.com/a/14844/118712 Although my guess is that your feature request of automatcally filling out a total based on the entries to other fields will be difficult to implement. – Markus G. Aug 11 '21 at 15:46

1 Answers1

2

you must give the textfield unique names. And then you can use javascript, eg.

\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:forms@stackexchange.invalid?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}

enter image description here

Ulrike Fischer
  • 327,261