The color changing functionality takes advantage of the trick that if there are annotation (markup) objects in a stamp, they can be manipulated by a script immediately before the stamp is placed. When the stamp is placed, all these objects get flattened into the stamp by PDF XChange. I've only tested in PDF XChange 10.5.2.
One still needs to go through the usual rigmarole to get the stamp ID, but all of the code for generating the dialog, and filling in form fields, is handled.
Examples
I'll post some usage examples below in separate posts.
Example 1: Dialog with one field, color picker and auto-increment
Example 2: Multiple form fields, and auto-calculated date field
Example 3: Stamp Properties: Setting stamp subject based on form field value
Example 4: Using form fields and functions to set other properties and stamp colors
Example 5: Adding additional colors to stamps
Example 6: Running scripts before the stamp is placed, and changing properties of annotations in the stamp
Example 7: Weld symbol stamps that start the arrow tool
Usage
Assign a custom action to one of the form fields. For the custom action, call this function.
Code: Select all
xutil.stampDialog( stampID, dialogConstructor[, dialogConstructor, ...])
dialogConstructor is an object that has various key:value pairs for each dialog field you want to create. The keys and their acceptable values are as follows:
field: "FieldName" (optional) the form field in the stamp that will be filled from the dialog.
- FieldName is also the globals key under which the entered value is stored for the next time the stamp is used. If you skip the field parameter, it will create static text from description unless it's a 'button' in which case this parameter is ignored.
- description: "Field description text" (optional only if there's a field paramenter) If null or omitted it skips the dialog and assigns the default value - use an empty string "" if no description needed.
- value: "Default value" or function(), (optional assigns "" if omitted)
For radio, list box or combo box, the format is [item1, item2, ...] The items can either be a string, in which case that is what is both displayed and returned, or an object {value:"code", description:"Text description"} in which case the description is displayed, but the value is returned. - type: (optional) type of dialog box item - if omitted gets type from field (check_box, radio, list_box, hier_list_box, static_text, edit_text, popup, button, cluster, view)
- handler( dialog ): (optional) function to call when the dialog item is clicked or changed.
Required for type: 'button', where the field parameter is ignored.
'this' is the dialog monitor and 'dialog' is the dialog object.- Note that the dialog monitor is supplied with two properties to help decipher which field maps to which dialog element:
this.fields is a list of all fields, and their index is the index on the item_id for dialog elements 'db00' is the first, 'db01' second, etc
this.radios is a list of radio buttons [field, returnValue]; item_id for radios is 'rd00', 'rd01', etc based on the index in the array and the group_id is the field item_id
- Note that the dialog monitor is supplied with two properties to help decipher which field maps to which dialog element:
- increment: value (optional) 'value' is either:
- a number to increment by (ie 1, -2, etc). Increment happens before the dialog is shown; or
- an array [incVal, format] where 'incVal' is the number to increment by (or zero), and 'format' is one of the following: r,R,c,C,nWidth (roman lowercase, roman uppercase, alphabet lowercase, alphabet uppercase, number of digits)
- labelWidth: (optional) sets the width of the auto-generated label on edit_text, popup, list_box
- ok( stamp ): (optional) function to run after the ok button is pressed.
'stamp' is the current stamp, and 'this' is the current dialogConstructor, - globals: for each of the dialogObjects, this is the saved global variables for this stamp, in the form {key:value, ...} where key is the fieldName. It has access to any saved field values for the whole stamp file. It is updated with the information from the dialog box before ok() is run. Note: If using globals to get the values of other fields, field values are updated in globals in the order they are processed, so data for dialogConstructors below the current one will be old (from the previous time the stamp was used)
- setProp: (optional) stamp property name to set from the value of this field, or {property:value} object to supply the value.
- (optional) other parameters can be passed to dialog such as 'width', 'height', 'char_width', 'char_height', 'font', 'bold', 'italic', 'alignment', 'multiline', 'multi_select', 'separator:1', 'align_children',etc
colorX: defaultColor or function()
- description: "Color Dialog Description", (optional) sets a color picker dialog - if null or omitted then no dialog and it assigns the default color
- strokeColor: true (optional) to set the strokecolor of the stamp
To get the color on objects to change, they need to be annotations or fields. Annotation subject or author, and Field Tooltip or Mapping Name must contain the text %colorX TFS% where X is an optional index if there are multiple color pickers and T,F,S is for text, fillcolor or strokeColor is set
For example: %color S% to set the text and stroke color if there's only one color dialog item
The globals property will be updated with all current field values before the colors are applied
The above example will throw a javascript exception if someone with the stamp file is missing xutil.stampUtils.js (ie they only got a copy of the stamp file). I'm not sure why this would happen

Code: Select all
// alternative that checks first if xutil.stampDialog method exists:
if ("object" === typeof xutil) xutil.stampDialog?.( stampID, dialogConstructor, ... );
Installation
Unzip and save in JavaScripts folder, then restart PDF XChange. You may need to make the folder. Either in
C:\Users\[USERNAME]\AppData\Roaming\Tracker Software\PDFXEditor\3.0\Javascripts
OR so that all users have access:
C:\Program Files\Tracker Software\PDF Editor\Javascripts The above has minified code. In the spirit of open source, here is the source code: Limitations
- Once a stamp is started, I don't think there's anything a script can do to stop it. I used to have a Cancel button on stamp dialogs, but it couldn't cancel the stamp placement. I started using the cancel button as a "reset" (ie I'd clear all the fields), but it's such a rare occurrence that I need to clear the fields (I can go through and clear them myself before placing the stamp if I absolutely want a blank stamp). So I only show an OK button now.
- Dynamic stamps relying on this tool must be used on applications able to run this tool! It is not tested on software other than PDF XChange Editor. I didn't use any PXCE special javascript, so it may work on other applications, although they tend to not be as up to date on javascript. Let me know. If it's just a matter of minor tweaks, I'll try to do them. But I'm not willing to re-write it in an earlier version of javascript, for example.