Free

Free coded apps to suit all. No sign up, no email, usable offline, updates when I can, feedback welcome. Send feedback

Behind the scenes

Formats and calculations for PDF form fields in PDF by Zaweba

Set number, currency, date and time formats, ranges and totals on PDF form fields in PDF by Zaweba, worked out without a script engine.

Formats and calculations for PDF form fields in PDF by Zaweba

A form that adds up its own totals feels clever to the person filling it, and it saves them mistakes. In PDF by Zaweba every field has properties covering its appearance, its options, its format, the range of values it accepts and any calculation it carries. Getting those right is what turns a set of boxes into a form that helps people.

You reach the properties from Prepare form, by selecting a field and editing it. The rest of this article goes through what each group of settings is for.

Appearance and looks

Appearance covers how the field shows on the page. Three looks are worth knowing. Auto-size lets the text shrink to fit the box, which helps when answers vary a lot in length. Comb spreads the characters out evenly across the box, one per cell, which is exactly what you want for things like reference numbers printed on a row of little squares. Password hides what is typed, for the rare form that asks for something private on screen.

Options depend on the kind of field. A drop-down or list needs its choices. A check box needs to know what it means when ticked. Take time over these, because they decide what answers are even possible.

Formats

Formats control how a value is shown and what may be typed. The formats on offer are number, currency, percentage, date, time and special. A currency field shows money tidily. A percentage field shows a percentage. A date or time field keeps entries in one consistent shape, so you never get a mix of ways of writing the same date.

Formats also make data more useful later. If you export the form's data to a spreadsheet, fields with a proper number format give you clean numbers to work with, rather than text with stray symbols.

Ranges

A range sets the smallest and largest value a field should hold. It is a simple guard against obvious slips, such as a quantity of minus three or a percentage over a hundred. Set ranges on anything where a value outside sensible limits must be a mistake.

Calculations, and how they run

Calculations let a field work out its value from others: a line total from quantity and price, a grand total from the line totals, a figure with tax added. This is where the behind the scenes part is interesting.

Many PDF forms rely on small scripts for their sums, and those need a script engine to run. PDF by Zaweba carries out field calculations without a script engine, and in the order the form specifies. That order matters. If the grand total were worked out before the line totals, it would be wrong until something forced a second pass. Following the form's own order means the figures come out right first time.

It also keeps things safer. A program that never runs scripts can't be tricked by one, which fits with the app's general approach of showing documents as they are without running anything hidden inside them.

Fields that work elsewhere too

Fields made here carry standard calls that other readers run too. In practice that means a form you build in PDF by Zaweba should keep its formats and totals when someone opens it in another PDF reader, rather than turning into plain boxes. That matters, because you rarely know which program the person filling your form will use.

Building and testing in order

Build the plain fields first and add formats and calculations once the layout is settled. Name fields clearly before writing calculations, since a calculation that refers to "Quantity1" is far easier to follow than one built on automatic names. Then test: fill in a few lines with simple numbers you can check in your head, and confirm every total. Try a value outside each range to see how the form deals with it.

When the totals are right and the formats tidy, save the form and share it. People filling it will never see the settings, only a form that quietly does the arithmetic for them.