TransWikia.com

Using formula in a fillable PDF forms made with LaTeX?

TeX - LaTeX Asked by Cyril Langlois on January 24, 2021

I used the hyperref LaTeX package to make fillable PDFs in order to evaluate student’s works. It’s a lists of boxes in which notes are given, with :
TexField[name=note1,value=0,width=33pt,height=12p]{} (in a Form environment)

Now, I want to add a last box where the values of the preceding ones would be automatically summed, as in an LibreOffice or Excel Spreadsheet.
It seems this could be achievable with JavaScript commands, like explained on this (french) blog. I’m not familiar with JavaScript langage, but I try this :

PushButton[name=go,calculate={var a=this.getField("note1"); var b=this.getField("note2"); var c=this.getField("note3") etc...;
var Total=this.getField("Total"); Total.value=(a.value+b.value+c.value...)}]{Get sum}
TextField[name=Total,width=33pt,height=12pt,value=''Total''.value,readonly=true]{}

But the sum never appears in the last box. It seems that the getField instruction doesn’t work, or that I don’t have the right way to display the result.

Could someone says what’s wrong, or give me another trick to obtain the expected result ?

Here the example found on the blog I’ve cited :

documentclass[11pt]{exam}
usepackage[utf8]{inputenc}
usepackage[T1]{fontenc}
usepackage[full]{textcomp}
usepackage[a4paper,top=2cm,bottom=1.75cm]{geometry}
usepackage{amsmath,amssymb,amsfonts}
usepackage{hyperref}

begin{document}
begin{Form}
  TextField[name=nb1,value=0]{Valeur numero 1}
  TextField[name=nb2,value=0]{Valeur numero 2}
  TextField[name=moy]{Moyenne des deux}
  PushButton[name=go,
              onclick={var a = this.getField("nb1");var b=this.getField("nb2");
                       var moy=this.getField("moy");moy.value=(a.value+b.value)/2
                       }
              ]{Calculate}
end{Form}

end{document}

When I add a value to the nb1 or nb2 boxes, the mean value (moy) is not calculated.

Thanks a lot,

Cyril

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP