10.07.2015 Views

Download - Multivac!

Download - Multivac!

Download - Multivac!

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

3.4.2 Formatting Options for Text FieldsIn Acrobat it is possible to specify various options for formatting the contents of a textfield, such as monetary amounts, dates, or percentages. This is implemented via customJavaScript code used by Acrobat. PDFlib does not directly support these formatting featuressince they are not specified in the PDF reference. However, for the benefit ofPDFlib users we present some information below which will allow you to realize formattingoptions for text fields by supplying simple JavaScript code fragements with theaction option of PDF_create_field( ).In order to apply formatting to a text field JavaScript snippets are attached to a textfield as keystroke and format actions. The JavaScript code calls some internal Acrobatfunction where the parameters control details of the formatting.The following sample creates two keystroke and format actions, and attaches them toa form field so that the field contents will be formatted with two decimal places and theEUR currency identifier:keystroke_action = p.create_action("JavaScript","script={AFNumber_Keystroke(2, 0, 3, 0, \"EUR \", true); }");format_action = p.create_action("JavaScript","script={AFNumber_Format(2, 0, 0, 0, \"EUR \", true); }");String optlist = "font=" + font + " action={keystroke " + keystroke_action +" format=" + format_action + "}";p.create_field(50, 500, 250, 600, "price", "textfield", optlist);Cookbook A full code sample can be found in the Cookbook topic interactive/form_textfield_input_format.In order to specify the various formats which are supported in Acrobat you must use appropriatefunctions in the JavaScript code. Table 3.4 lists the JavaScript function namesfor the keystroke and format actions for all supported formats; the function parametersare described in Table 3.5. These functions must be used similarly to the example above.Table 3.4 JavaScript formatting functions for text fieldsformatnumberpercentagedatetimespecialJavaScript functions to be used for keystroke and format actionsAFNumber_Keystroke(nDec, sepStyle, negStyle, currStyle, strCurrency, bCurrencyPrepend)AFNumber_Format(nDec, sepStyle, negStyle, currStyle, strCurrency, bCurrencyPrepend)AFPercent_Keystroke(ndec, sepStyle), AFPercent_Format(ndec, sepStyle)AFDate_KeystrokeEx(cFormat), AFDate_FormatEx(cFormat)AFTime_Keystroke(tFormat), AFTime_FormatEx(cFormat)AFSpecial_Keystroke(psf), AFSpecial_Format(psf)Table 3.5 Parameters for the JavaScript formatting functionsparametersnDecexplanation and possible valuesNumber of decimal places3.4 Interactive Elements 71

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!