Execute an Action

<< Click to Display Table of Contents >>

Navigation:  Tasks > Internal Actions >

Execute an Action

To execute an action you can use either the command

 

COMPDF_ACTION  (580)

or

COMPDF_ACTIONNR  (581)

 

COMPDF_ACTION expects the action name + "=" + the parameter as comma separated list in the string parameter. If the action was not found, the result is -2. Otherwise the usual result is returned, -1 means "default".

 

procedure TForm1.Executeanaction1Click(Sender: TObject);

var vals : array[0..1] of string;

begin

   vals[0] := 'DrawAnnotHighlight';

   vals[1] := '"Color=Red","Alpha=50"';

   if InputQuery('Execute Action',['Name','Parameter'],vals) then

   begin

       if pdf.CommandStr(COMPDF_ACTION, vals[0] + '=' + vals[1]   )=-2 then

          ShowMessage('The action ' + vals[0] + ' was not found');

   end;

end;

 

COMPDF_ACTIONNR expects the action number (high word=group, low word = operation) in the integer parameter and the optional parameters in the string parameter.  If the action was not found, the result is -2.

 

This code works as the example above - it first retrieves the number of the named action. Such a number is also used for COMPDF_ACTION_READ which is discussed below.

 

procedure TForm1.Executeanaction1Click(Sender: TObject);

var vals : array[0..1] of string;

    acn : Integer;

begin

   vals[0] := 'DrawAnnotHighlight';

   vals[1] := '"Color=Red","Alpha=50"';

   if InputQuery('Execute Action',['Name','Parameter'],vals) then

   begin

      acn := pdf.CommandStr( COMPDF_ACTION_READ, '?' + vals[0] );

      if acn<=0 then

           ShowMessage('The action ' + vals[0] + ' was not found')

      else pdf.CommandStrEx(COMPDF_ACTIONNR, vals[1], acn );

   end;

end;

 

 

Optionally parameters can be passed to the execution methods. Which parameters are required can be automatically retrieved using COMPDF_ACTION_READ with the action number and the string parameter set to "param" or "paramkind":

 

 param     := WPViewPDF1.Command(COMPDF_ACTION_READ, 'param', acn );

 paramkind := WPViewPDF1.Command(COMPDF_ACTION_READ, 'paramkind', acn );

 

Please see our Delphi and Visual Studio example code.

 

param is a bit field. Bit 2 is set, if a string parameter is expected by the action.

 

   1=require Intpar,

   2=require string par,

   4=read intpar,

   8=read string par,

   16 Boolean,

   32 OPTIONAL String  - usually properties

   64 - this is a GUI Boolean, Show true/false action

 

paramkind can have the following values (some are reserved)

 

   0: Pagenr as Int or string

   1: Fontname as string

   2: Color as Int or string

   3: PDF filename as string OPEN

   4: PDF filename as string SAVE

   5: text filename as string OPEN

   6: text filename as string SAVE

   7: image file name as string  OPEN

   8: JPEG file name as string   SAVE

   9: type @ options_comma_list

   10: options_comma_list

   11: options_for_DrawObjects

   12: Zoom Value as Int

   13: JPEG image file name as string to OPEN passed as "file=...",... + other params

   14: some text as string  passed as "text=...",... + other params

   15: Transparency in range 0..255

   16: Boolean  "true"/"false" "1"/"0"

   17: Fontsize as number in string

   50: Ask $hint$ yes/now

 

Options for the draw objects and annotations are usually passed as comma separated list, i.e "Color=Red","Alpha=50".

 

Drawobjects and annotations support this property names

 

Color - this is the color as HTML color

Alpha - this is the transparency, 1=transparent, 255=solid

 

Font - this is the font for a freetext annotation

Font-Size - the size for the text

Font-Color - the color for the text

 

The DrawAnyAnnot action also accepts the parameter

type=pdf annotation type, i.e. "type=Link"

 

Example:

   pdf.CommandStrEx( COMPDF_ACTION,

      'DrawAnnotFreetext="font-color=red","font-size=18","font=courier new"', 0);

 

 

Internally the options are stored as XML.

 

Annotations are saved as PDF objects and can have additional parameters which can also be set using the parameter list.

 

The name of each of the additional PDF properties must start with "prp.". (lowercase!)

 

After that a single letter differentiate between the possible parameter types - all are case sensitive!

s - this is a PDF string type

n - this is a PDF name type

v - this is any value type

i - this is an integer

a - this is an array type, it will be written between [ and ].

d - this is a dictionary - it will be written between << and >>.

r - this make it possible to use page references.

    Internally the function will replace all #nnn or #{xxx} values by the correct page references or /null if not found.

    This feature can be used to write a /Dest page reference to be used by a link (see example).  

 

It is also possible to create parameters for sub dictionaries by simply specifying the name of the dictionary, a "." and then the  property as described above.