0

I have written a form with LaTeX using hyperref and I have embedded some Java code (using insdljs). I am not a Java programmer at all, but I find it quite intuitive, at least for what I am doing.

Hereafter there is a minimum example:

\documentclass[12pt,a4paper]{article}
\usepackage{hyperref}
\usepackage[pdftex]{insdljs}

\begin{insDLJS}[setcom]{setcom}{JavaScriptAtDocumentLevel}

// set days array
var days = [["gg"],["01"],["02"],["03"],["04"],["05"],["06"],["07"],["08"],["09"],["10"],["11"],["12"],["13"],["14"],["15"],["16"],["17"],["18"],["19"],["20"],["21"],["22"],["23"],["24"],["25"],["26"],["27"],["28"],["29"],["30"],["31"]];

//populate the values to giorni and others
this.getField("giorni1").setItems(days);
this.getField("giorni2").setItems(days);
this.getField("giorni3").setItems(days);

// set months array
var months = ["mm","gen","feb","mar","apr","mag","giu","lug","ago","set","ott","nov","dic"];

// populate the values to mesi and others
this.getField("mesi1").setItems(months);
this.getField("mesi2").setItems(months);
this.getField("mesi3").setItems(months);

// set future years
var futureYear = [["aaaa","aaaa"],["2019","19"],["2020","20"],["2021","21"],["2022","22"],["2023","23"],["2024","24"],["2025","25"],["2026","26"],["2027","27"],["2028","28"],["2029","29"],["2030","30"],["2031","31"],["2032","32"],["2033","33"],["2034","34"],["2035","35"],["2036","36"],["2037","37"],["2038","38"],["2039","39"],["2040","40"],["2041","41"],["2042","42"],["2043","43"],["2044","44"],["2045","45"]];

// populate the values to annofuturo
this.getField("annofuturo1").setItems(futureYear);
this.getField("annofuturo2").setItems(futureYear);
this.getField("annofuturo3").setItems(futureYear);

\end{insDLJS}

\begin{document}

\begin{flushleft}
\normalsize

\begin{Form} 

\fbox{
  \parbox{\textwidth}{
    \ChoiceMenu[print,combo,edit=false,name=giorni1,bordercolor={0 0 0},width=0.5cm,default=]{Data}{}\hspace{-0.16cm}
    \ChoiceMenu[print,combo,edit=false,name=mesi1,bordercolor={0 0 0},width=1.4cm,default=]{}{}\hspace{-0.16cm}
    \ChoiceMenu[print,combo,edit=false,name=annofuturo1,bordercolor={0 0 0},width=1.5cm,default=]{}{}
    }
}

\fbox{
  \parbox{\textwidth}{
    \ChoiceMenu[print,combo,edit=false,name=giorni2,bordercolor={0 0 0},width=0.5cm,default=]{Data}{}\hspace{-0.16cm}
    \ChoiceMenu[print,combo,edit=false,name=mesi2,bordercolor={0 0 0},width=1.4cm,default=]{}{}\hspace{-0.16cm}
    \ChoiceMenu[print,combo,edit=false,name=annofuturo2,bordercolor={0 0 0},width=1.5cm,default=]{}{}
    }
}

\fbox{
  \parbox{\textwidth}{
    \ChoiceMenu[print,combo,edit=false,name=giorni3,bordercolor={0 0 0},width=0.5cm,default=]{Data}{}\hspace{-0.16cm}
    \ChoiceMenu[print,combo,edit=false,name=mesi3,bordercolor={0 0 0},width=1.4cm,default=]{}{}\hspace{-0.16cm}
    \ChoiceMenu[print,combo,edit=false,name=annofuturo3,bordercolor={0 0 0},width=1.5cm,default=]{}{}
    }
}

\end{Form}
\end{flushleft}
\end{document}

The two problems I have are:

  1. I want my tex file as compact as possible. Imagine that days, months and future years will be called several times and for each \ChoiceMenu[parameters]{label}{choices} I do not want to repeat the {choices} all the times, I want to store them and assign them (or call them).
  2. The selected choices in my \ChoiceMenu are not saved in the pdf file when, after selecting them, I save, close and open the pdf again. It is like the pdf file gets reset each time I open it. Oddly enough, the pdf preview inside texstudio has the correct choices stored and displayed.

The two problems are related, i.e. if I do not declare any java variable and put all the entries in the {choices} field every time I do not have problem number 2, but I do have problem number 1.

So, my question is: do you know any other way to save space and time (problem 1) and/or make the changes to the pdf file effective (problem 2)?

So far, I have made some thoughts, which I do not know how to put into practice:

  1. I could e.g. declare an array of strings (like in python) and call it instead of repeating the {choices} for each \ChoiceMenu. Is there anything alike in latex?
  2. I could add some [parameters] to the \ChoieMenu like onexit={}, but as I am not a Java expert I do not know what to put in it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.