Your second PDF form with Scribus (and Javascript)
Work in progress!
Introduction
JavaScript functions in a PDF document
Teaching material will be made available for download asap.
Adding new functions
Go to Edit/Javascripts... and click on Add. Choose a name for your new function and click on OK to launch the built-in JavaScript editor.
Let us call our first function RunOnLaunch and start with a simple alert that will be displayed on launching the PDF formular in Adobe Reader:
function RunOnLaunch() { app.alert('Welcome to the Scribus Demo Form!'); }
Launching JavaScript functions
Go to File/Export/Save as PDF and click on the Viewer tab. Choose the JavaScript to be executed from the Special Actions drop down list. Save the PDF document and open in with the Adobe Reader to see how it works.
Adding JavaScript to PDF form elements
Validate form fields
if(!this.getField('field1').value) { app.alert('Please fill a number into field 1'); } else if (!this.getField('field2').value) { app.alert('Please fill a number into field 2'); }
Calculate form field values
if(!this.getField('field1').value) { app.alert('Please fill a number into field 1'); } else if (!this.getField('field2').value) { app.alert('Please fill a number into field 2'); } else { app.alert('Adding field1 to field2 and putting the result into field3'); this.getField('field3').value = this.getField('field1').value + this.getField('field2').value; app.alert('and now add 20% VAT to the result, if checkbox1 is checked '); var v = this.getField('checkbox1'); if(v.value=='Yes') var vat = this.getField('field3').value * 0.2; else var vat = 0; this.getField('field3').value = this.getField('field3').value + vat; }
(c)
The content of this page is available under the Creative Commons Attribution-ShareAlike Licence and Free Documentation Licence
If you alter, transform, or build upon this work, you may distribute the resulting work either under one or under both of the abovementioned licences.