Annotation support

<< Click to Display Table of Contents >>

Navigation:  Tasks >

Annotation support

This feature was added to WPViewPDF V4 PLUS.

 

The command COMPDF_ACRO_MAKEDRAWOBJ with a string and an integer parameter can be used to convert all or certain annotations in existing PDF files  into objects which can be selected, moved and deleted.

 

The string parameter selects the type of annotations which are converted. The subtyle name can be specified with "+" to be included or "-" to be excluded. Also supported is "+all" and "-all".

 

Fields use the subtype "widget". Here it is possible to further differentiate using the fieldtype: "ftTx", "ftCh" and "ftBtn" are possible.

 

Example:

"+all,-popup" will convert all annotations except for popup

"-all,+ftTx" will only convert text fields.

"-all,+ftTx,+square,+highlight" will only convert the types which can be currently created by WPViewPDF.

 

The integer parameter of command COMPDF_ACRO_MAKEDRAWOBJ can use this bits:

1: The created objects cannot be selected

2: The created objects cannot be moved or sized (create locked objects)

4: The created objects cannot be deleted (Deletion is supported by WPViewPDF V4 only)

1024: Read the fieldflag to select locked and readonly state

2048: The object may be moved, but not resized

4096: The widgets (edit fields) do not display an inplace editor on click.

 

8192: Auto mode - execute the command whenever a file was loaded. (recommended)

   

COMPDF_Ann_SetAnnotSaveMode - Enables saving of annotations which have been added to the page

 

Command(COMPDF_Ann_SetAnnotSaveMode, 1);

 

This property bits are supported:

 

 1 : Add the draw annotations which were created on the page

 2 : Recreate all annotations, also those which were not modified

 4 : reserved

 8 : selectively remove all widgets while saving. Must be combined with 1

 16: selectively remove all non widgets while saving. Must be combined with 1

 

You can "flatten" the PDF annotations. Since the annotations have been rendered into the PDF pages you probably do not want to save them. Use COMPDF_Ann_SetAnnotSaveMode, (1+8+16) to save the PDF without.

 

To flatten the annotations use command

 

command( COMPDF_RenderDrawobjects, 1+32 )

 

 

also see command COMPDF_Ann_ModifyAddProps.

 

COMPDF_Ann_AddAnnotation is used to either add an annotation at once, or let the user draw a frame to where the annotation is created. It is possible to specify a AcroField ID for a new widget annotation.

 

 

COMPDF_Ann_AddAnnotation requires the address of a parameter structure:

 

  TWPAddAnnotationParam = record

       Mode   : Integer;

       pageno : Integer;

       x,y,w,h : Single;

       typ : PWideChar;

       Props: PWideChar; // CommaList TStrings;

       PopupID : PWideChar;

       AddAnnotMode : Integer; // Bitfield: "TWPAddAnnotMode"

       // 1   wpAddWidget,   // Name is FT, not subtype

       // 2   wpAddPopup, // Add Popup - Append Reference to PopupList

       // 4   wpAddAlsoAcroField, // Also adds a field in the acrofield tree at the given name-path

       //     does not work if AcroXID<>0

       // 8   wpAddThenSelectObject, // After object creation the user may select and move the object

       // 16  wpAddAtMouseRect, // The user may draw one rect and an annot is created

       // 32  wpAddAtMouseRectContinue // The user may create another after the first

       // 64  wpSelectTextToQuadPoints // The user may select text and the highlight will be created there

       // This also activates the text selection mode!

 

       FieldPathName : PWideChar;

       FieldValue    : PWideChar;

       AcroXID : Integer;

       Reserved  : Integer; // Must be 0

   end;

 

The element Props controls the properties and the type of the new annotation. It must be provided as a comma separated list. The properties which should be written to PDF can be encoded here. The type of the PDF property is determined by the prefix s, a and n:

 s.  creates a string, i.e. "s.Contents=This is the contents of a field"

 a.  creates an array, i.e. "a.B=0 0 0" selects the border color

 n.  writes any number, i.e. "n.F=123"

 

The values color and alpha are understood without a prefix, since they are not written to PDF.

 

The element typ may be the name of the annotation. Please use "highlight" or "square". To create a widget use "edit" or "memo" which are interpreted internally.

 

Please note: "F=4" must be defined, otherwise the annotation is visible on screen but will not be printed by Acrobat Reader.

 

 

With WPViewPDF PLUS it is also possible to modify a selection of properties of the currently selected annotations.

 

This commands are used to implement a property inspector for fields and annotations

 

  COMPDF_Ann_XMLGetFromAcrofield = 572; // Read data from selected fields. Use StrParam for params which are not shared

  COMPDF_Ann_XMLGetFromAnnots = 573; // read data from select annots.

  COMPDF_Ann_XMLSetToAcrofield = 574; // Read data from selected fields. Dont modify params which use StrParam as param

  COMPDF_Ann_XMLSetToAnnots = 575; // read data from select annots.  Return count of modified objects.

 

Also see example.

 

If you need to convert the annotations into regular PDF drawing code ("flatten" a PDF file) use command

  COMPDF_RenderDrawobjects