Generalhyperref | JavaScript and Forms

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
chrisfortytwo
Posts: 1
Joined: Thu Nov 03, 2011 7:23 pm

hyperref | JavaScript and Forms

Post by chrisfortytwo »

I am trying to produce a PDF form with Javascript calculations that I can either export or save. Acrobat Reader will run the Java correctly, but won't let me save or export my form data to PDF.
I've tried evince and a couple other the GPL PDF viewers, but they don't run Java correctly (and sometimes won't even use the form correctly).

I've tried opening it in Acrobat Professional, and changing the setting to "readable", but somehow, my JavaScript code gets corrupted.

I'm wondering if the problem is because I'm mixing {insdljs} with {hyperref}

Does anyone have any suggestions for somehow making this do what I want?

Below is a sample of some of the things I am trying to do:
(change borders on Open, do calculations, hide fields during print).

Code: Select all

\documentclass[12pt, letterpaper]{article}
\usepackage[pdftex,colorlinks=true,
	pdftitle={Sample},
	pdfsubject={Reader},
	pdfauthor={Chris},
	pdfpagemode=UseNone,
	pdfstartview=FitH,
	pagebackref,
	pdfhighlight={/N}]
{hyperref}
\usepackage[pdftex]{insdljs}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%   JAVA SCRIPT
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\immediate\pdfobj{
<<
	/WP << /S /JavaScript /JS (prePrint();) >>
	/DP << /S /JavaScript /JS (postPrint();) >>
>>
}
\pdfcatalog{/AA \the\pdflastobj\space 0 R}
\begin{insDLJS}[charsheet]{charsheet}{Document Level JavaScript}
function onOpen() {
	this.getField("Name").borderStyle = border.u;
}

function calc() {
	this.getField("Sum").value = this.getField("One").value + this.getField("Two").value;
}

function prePrint(){
	this.getField("One").hidden = true;
}

function postPrint(){
	this.getField("One").hidden = false;
}

\end{insDLJS}
\OpenAction{/S /JavaScript /JS (onOpen();)}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  DOCUMENT
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\begin{Form}

\begin{tabular}{l}
\TextField[name={Name}, charsize={14pt}, width={2.5in}, bordercolor={0 0 0}]{}
\end{tabular}

\vspace{1cm}

\begin{tabular}{lllll}
\TextField[name={Sum}, align=1, bordercolor={0 0 0}, readonly=true]{} & = & 
\TextField[name={One}, align=1, bordercolor={0 0 0}]{} & + &
\TextField[name={Two}, align=1, bordercolor={0 0 0}]{}
\end{tabular}

\vspace{1cm}

\begin{minipage}{2in}
\PushButton[name=calculate, charsize=10pt, onclick={calc()}, bordercolor={0 0 1}] {Recalculate}
\end{minipage}

\end{Form}
\end{document}
I use pdflatex on Ubuntu 11.10 (home) and Fedora 13 (school). I used a trial version of Acrobat Professional X to attempt changing permissions.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Post Reply